Created
July 22, 2024 18:35
-
-
Save Dref360/99efc4c9c392351a9e128a8d26afcea1 to your computer and use it in GitHub Desktop.
Simple example using outlines and phi-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
from enum import Enum | |
from typing import Optional | |
import outlines | |
from pydantic import BaseModel | |
class Competitors(str, Enum): | |
RoboCorp = "RoboCorp" | |
DoEvil = "DoEvil" | |
PearPC = "PearPC" | |
class RenewalDate(BaseModel): | |
competitor_name: Optional[Competitors] = None | |
renewal_date: Optional[date] = None | |
@outlines.prompt | |
def extract_competition_renewal(conversation, today): | |
""" | |
You will be provided with a conversation with one of our customer. | |
Your task is to extract the renewal date of our customer with one of our competitors. | |
If you can't find it, output None. | |
Today is {{ today }}. | |
Conversation | |
Customer: {{ conversation }} | |
""" | |
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct") | |
generator = outlines.generate.json(model, RenewalDate) | |
generator( | |
extract_competition_renewal( | |
conversation="Our contract is going well, we're super happy with you.", | |
today="2024-07-01", | |
) | |
) | |
# >>> RenewalDate(competitor_name=None, renewal_date=None) | |
generator( | |
extract_competition_renewal( | |
conversation="Our contract with RoboCorp is coming up in September, we're looking for alternatives.", | |
today="2024-07-01", | |
) | |
) | |
# >>> RenewalDate(competitor_name='RoboCorp', renewal_date=datetime.date(2024, 9, 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment