-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (23 loc) · 858 Bytes
/
utils.py
File metadata and controls
30 lines (23 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from openai import OpenAI
from dotenv import load_dotenv
import os
import json
# Load environment variables from .env file
load_dotenv()
# Initialize OpenAI client with environment variables
client = OpenAI(
api_key=os.getenv("VOLCES_API_KEY"),
base_url=os.getenv("VOLCES_BASE_URL", "https://ark.cn-beijing.volces.com/api/v3"),
)
default_model = os.getenv("VOLCES_MODEL", "ep-20250210182716-gfw9b")
def call_model(user_content, system_content="", response_format="text", model=default_model):
completion = client.chat.completions.create(
model=model,
response_format={"type": response_format},
temperature=0,
messages=[
{"role": "system", "content": system_content},
{"role": "user", "content": user_content}
]
)
return completion.choices[0].message.dict()["content"]