-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm_configs.py
More file actions
55 lines (51 loc) · 1.86 KB
/
llm_configs.py
File metadata and controls
55 lines (51 loc) · 1.86 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
temperature = 0.0
aliyun_key = "set your own key"
qwen32b_config = {"model": 'qwen2.5-32b-instruct',
"api_key": aliyun_key,
"base_url":"https://dashscope.aliyuncs.com/compatible-mode/v1",
"temperature": temperature,
"cache_seed": None,
"price" : [0.0, 0.0]}
openai_key = "set your own key"
openai_base_url = "set your own base url"
gpt35_config = {"model": "gpt-35-turbo",
"api_type": "azure",
"api_key": openai_key,
"temperature": temperature,
"cache_seed": None,
"base_url": openai_base_url,
"api_version": "2025-01-01-preview"}
gpt4omini_config = {"model": "gpt-4o-mini",
"api_type": "azure",
"api_key": openai_key,
"temperature": temperature,
"cache_seed": None,
"base_url": openai_base_url,
"api_version": "2025-01-01-preview"}
from openai import AzureOpenAI
from openai import AsyncAzureOpenAI
import asyncio
async def get_completion(prompt, model='gpt-4o-mini', temperature=0):
client = AsyncAzureOpenAI(
api_key = openai_key,
api_version = "2025-01-01-preview",
azure_endpoint = openai_base_url,
)
messages = [{"role": "user", "content": prompt}]
import time
for attempt in range(10):
try:
response = await client.chat.completions.create(
model=model,
messages=messages,
temperature=temperature,
)
break
except Exception as e:
if attempt < 9:
print(f"Attempt {attempt+1} failed with error: {e}. Retrying in 30 seconds...")
await asyncio.sleep(30)
else:
print(f"All 10 attempts failed. Last error: {e}")
raise
return response.choices[0].message.content