23 lines
547 B
Python
23 lines
547 B
Python
import os
|
|
|
|
from openai import OpenAI
|
|
from openai._types import Timeout
|
|
|
|
|
|
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),
|
|
)
|
|
|
|
response = client.chat.completions.create(
|
|
model=os.environ.get("OPENAI_MODEL", "llama3"),
|
|
messages=[{"role": "user", "content": "Hello!"}],
|
|
)
|
|
print(response.choices[0].message.content)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|