mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-14 22:43:49 +00:00
Update chatgpt.py
This commit is contained in:
parent
1b615aedd2
commit
2ff9625d3f
@ -170,10 +170,7 @@ def chatgpt_generate_stream(
|
|||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
client = OpenAI(**openai_params)
|
client = OpenAI(**openai_params)
|
||||||
print("openai_params", openai_params)
|
|
||||||
print("payloads", payloads)
|
|
||||||
res = client.chat.completions.create(messages=history, **payloads)
|
res = client.chat.completions.create(messages=history, **payloads)
|
||||||
print(res)
|
|
||||||
text = ""
|
text = ""
|
||||||
for r in res:
|
for r in res:
|
||||||
if r.choices[0].delta.content is not None:
|
if r.choices[0].delta.content is not None:
|
||||||
@ -209,19 +206,23 @@ async def async_chatgpt_generate_stream(
|
|||||||
|
|
||||||
client = AsyncAzureOpenAI(
|
client = AsyncAzureOpenAI(
|
||||||
api_key=openai_params["api_key"],
|
api_key=openai_params["api_key"],
|
||||||
end_point=openai_params["base_url"],
|
|
||||||
api_version=api_version,
|
api_version=api_version,
|
||||||
azure_endpoint=os.getenv(
|
azure_endpoint=openai_params[
|
||||||
"AZURE_OPENAI_ENDPOINT"
|
"base_url"
|
||||||
), # Your Azure OpenAI resource's endpoint value.
|
], # Your Azure OpenAI resource's endpoint value.
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
from openai import AsyncOpenAI
|
from openai import AsyncOpenAI
|
||||||
|
|
||||||
client = AsyncOpenAI(**openai_params)
|
client = AsyncOpenAI(**openai_params)
|
||||||
res = await client.chat.completions.create(
|
|
||||||
messages=history, **payloads
|
res = await client.chat.completions.create(messages=history, **payloads)
|
||||||
).model_dump()
|
text = ""
|
||||||
|
for r in res:
|
||||||
|
if r.choices[0].delta.content is not None:
|
||||||
|
content = r.choices[0].delta.content
|
||||||
|
text += content
|
||||||
|
yield text
|
||||||
else:
|
else:
|
||||||
import openai
|
import openai
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user