-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: #1 add supports complex struct parsing with streaming #7
Conversation
I would love to get some feedback on the API: class MathProblem(BaseModel):
steps: List[str]
answer: Optional[int] = None
# Define handler
class Handler(BaseHandler):
def model(self):
return MathProblem
async def handle_partially_parsed(self, data: MathProblem) -> Optional[Terminate]:
if len(data.steps) == 0 and data.answer:
return Terminate() # something is wrong here, so we immediately stop
if data.answer:
self.ws.send(data.answer) #show to the user with WebSocket
async def terminated(self):
ws.close()
# Invoke OpenAI request
async def main():
resp = await client.chat.completions.create(
messages=[{
"role": "system",
"content":
"For every question asked, you must first state the steps, and then the answer."
"Your response should be in the following format: \n"
" steps: List[str]\n"
" answer: int\n"
"ONLY write the YAML, without any other text or wrapping it in a code block."
"YAML should be VALID, and strings must be in double quotes."
}, {"role": "user", "content": "1+3*2"}],
stream=True
)
await process_struct_response(resp, Handler(), 'yaml') |
cc @jogardi @MRYingLEE @yotammanor |
Hi @AlmogBaku, hope all is well! I read through the PR, but haven't found the time to try out the api. I can give some bikeshedding comments right away, if that helps let me kno. Either way I'll try to find time to address the core issues (but can't promise my time will allow, unfortunately). |
Right away feedback is most welcome:) |
This PR supports parsing JSON/YAML from the stream and processing it as a model.
Allows you to implement features such as #1