Undertone0809 / promptulate

๐Ÿš€Large language model automation and Autonomous Language Agents development framework. Build your LLM Agent Application in a pythonic way!
https://www.promptulate.cn/
Apache License 2.0
274 stars 29 forks source link

Add Stream JSON parser #625

Open Undertone0809 opened 2 months ago

Undertone0809 commented 2 months ago

๐Ÿš€ Feature Request

Currently, we cannot enable stream if setting output schema. Eg:

from typing import List
import promptulate as pne
from pydantic import BaseModel, Field

class LLMResponse(BaseModel):
    provinces: List[str] = Field(description="All provinces in China")

response: LLMResponse = pne.chat(
    messages="Please tell me all provinces in China.",
    output_schema=LLMResponse,
    model="gpt-4-1106-preview",
    stream=True,
)
print(response.provinces)

image

Need to build a json parser to parse stream type json data like this:

image

Undertone0809 commented 2 months ago

Here to see how to solve: