32 lines
965 B
Python
32 lines
965 B
Python
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(30, connect=5),
|
|
)
|
|
|
|
response = client.chat.completions.create(
|
|
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)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|