This commit is contained in:
Jason Liu
2023-10-24 15:08:44 -04:00
parent 3ecc25495f
commit 840cd63953
26 changed files with 424 additions and 54 deletions
@@ -64,7 +64,7 @@ def load_json_schema(json_schema_path: str) -> dict:
def generate_pydantic_model(json_schema_path: str):
input_path = Path(json_schema_path)
output_path = Path(f"./models.py")
output_path = Path("./models.py")
generate(
input_=input_path, input_file_type=InputFileType.JsonSchema, output=output_path
)
+3 -3
View File
@@ -11,9 +11,9 @@ from pydantic import BaseModel
class Type(Enum):
home = 'home'
work = 'work'
mobile = 'mobile'
home = "home"
work = "work"
mobile = "mobile"
class PhoneNumber(BaseModel):
+9 -7
View File
@@ -10,14 +10,14 @@ from jinja2 import Template
from models import ExtractPerson
import openai
import instructor
import instructor
instructor.patch()
app = FastAPI()
class TemplateVariables(BaseModel):
class TemplateVariables(BaseModel):
biography: str
@@ -26,7 +26,11 @@ class RequestSchema(BaseModel):
model: str
temperature: int
PROMPT_TEMPLATE = Template("""Extract the person from the following: {{biography}}""".strip())
PROMPT_TEMPLATE = Template(
"""Extract the person from the following: {{biography}}""".strip()
)
@app.post("/api/v1/extract_person", response_model=ExtractPerson)
async def extract_person(input: RequestSchema) -> ExtractPerson:
@@ -35,7 +39,5 @@ async def extract_person(input: RequestSchema) -> ExtractPerson:
model=input.model,
temperature=input.temperature,
response_model=ExtractPerson,
messages=[
{"role": "user", "content": rendered_prompt}
]
) # type: ignore
messages=[{"role": "user", "content": rendered_prompt}],
) # type: ignore