forked from lanqian528/chat2api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_format.py
More file actions
31 lines (26 loc) · 885 Bytes
/
test_format.py
File metadata and controls
31 lines (26 loc) · 885 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
31
import asyncio
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from chatgpt.ChatService import ChatService
from chatgpt.chatFormat import api_messages_to_chat
async def main():
token = None
try:
with open('data/token.txt', 'r') as f:
tokens = [line.strip() for line in f if line.strip()]
if tokens:
token = tokens[-1]
except Exception:
pass
cs = ChatService(token if token else "sk-123")
api_messages = [{"role": "user", "content": "Draw me a small simple icon of an apple."}]
cs.api_messages = api_messages
await cs.set_dynamic_data({"model": "gpt-4o"})
try:
res = await api_messages_to_chat(cs, api_messages, False)
print("Success:", res)
except Exception as e:
import traceback
traceback.print_exc()
asyncio.run(main())