🔄 Update chat completion logic and improve debugging output in main.py
This commit is contained in:
@@ -1,20 +1,29 @@
|
|||||||
import os
|
import os
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from openai._types import Timeout
|
from openai._types import Timeout
|
||||||
|
from openai.types.chat import ChatCompletionUserMessageParam, ChatCompletionSystemMessageParam
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
client = OpenAI(
|
client = OpenAI(
|
||||||
api_key=os.environ.get("OPENAI_API_KEY", "sk-dummy"),
|
api_key=os.environ.get("OPENAI_API_KEY", "sk-dummy"),
|
||||||
base_url=os.environ.get("OPENAI_API_BASE", "http://localhost:11434/v1"),
|
base_url=os.environ.get("OPENAI_API_BASE", "http://localhost:11434/v1"),
|
||||||
timeout=Timeout(timeout=30),
|
timeout=Timeout(30, connect=5),
|
||||||
)
|
)
|
||||||
|
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model=os.environ.get("OPENAI_MODEL", "llama3"),
|
model=os.environ.get("OPENAI_MODEL", "qwen-math-turbo"),
|
||||||
messages=[{"role": "user", "content": "Hello!"}],
|
messages=[
|
||||||
|
ChatCompletionSystemMessageParam(role="system", content="You are a useful assistant."),
|
||||||
|
# ChatCompletionUserMessageParam(**{"role": "user", "content": "Hello!"}),
|
||||||
|
ChatCompletionUserMessageParam(role="user", content="Hello!"),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
print()
|
||||||
|
pprint(vars(response))
|
||||||
|
print()
|
||||||
print(response.choices[0].message.content)
|
print(response.choices[0].message.content)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user