🔄 Update chat completion logic and improve debugging output in main.py
This commit is contained in:
@@ -1,20 +1,29 @@
|
||||
import os
|
||||
from pprint import pprint
|
||||
|
||||
from openai import OpenAI
|
||||
from openai._types import Timeout
|
||||
from openai.types.chat import ChatCompletionUserMessageParam, ChatCompletionSystemMessageParam
|
||||
|
||||
|
||||
def main():
|
||||
client = OpenAI(
|
||||
api_key=os.environ.get("OPENAI_API_KEY", "sk-dummy"),
|
||||
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(
|
||||
model=os.environ.get("OPENAI_MODEL", "llama3"),
|
||||
messages=[{"role": "user", "content": "Hello!"}],
|
||||
model=os.environ.get("OPENAI_MODEL", "qwen-math-turbo"),
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user