Files
instructor/examples/fastapi_app/script.py
T
2023-07-09 00:09:02 +08:00

51 lines
1.2 KiB
Python

from openai_function_call import OpenAISchema, dsl
from pydantic import Field
class SearchQuery(OpenAISchema):
query: str = Field(
...,
description="Detailed, comprehensive, and specific query to be used for semantic search",
)
SearchResponse = dsl.MultiTask(
subtask_class=SearchQuery,
description="Correctly segmented set of search queries",
)
task = (
dsl.ChatCompletion(name="Segmenting Search requests example")
| dsl.SystemTask(task="Segment search results")
| dsl.TaggedMessage(
content="can you send me the data about the video investment and the one about spot the dog?",
tag="query",
)
| dsl.TipsMessage(
tips=[
"Expand query to contain multiple forms of the same word (SSO -> Single Sign On)",
"Use the title to explain what the query should return, but use the query to complete the search",
"The query should be detailed, specific, and cast a wide net when possible",
]
)
| SearchResponse
)
import pprint
import json
print(json.dumps(task.kwargs, indent=1))
"""
{
"tasks": [
{
"query": "data about video investment"
},
{
"query": "data about spot the dog"
}
]
}
"""