aifeifei798 commited on
Commit
ee650ed
1 Parent(s): fa8835a

Upload test_openai_api_lmstudio.py

Browse files
Files changed (1) hide show
  1. test_openai_api_lmstudio.py +32 -26
test_openai_api_lmstudio.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from openai import OpenAI
2
 
3
  # Point to the local server
@@ -9,29 +10,34 @@ history = [
9
 
10
  # Open the file in read mode
11
  with open('Model_Test_Issues_zh_en_jp.txt', 'r', encoding='utf-8') as file:
12
- # Read each line from the file
13
- for line in file:
14
- print(line)
15
- line = line + ",用中文回复"
16
- # Add the line as the user's content to the history
17
- history.append({"role": "user", "content": line.strip()})
18
-
19
- # Generate the response
20
- completion = client.chat.completions.create(
21
- model="mod/Repository",
22
- messages=history,
23
- temperature=0.7,
24
- stream=True,
25
- stop=["### Evaluation:","<|end_of_text|>","Translation:"]
26
- )
27
-
28
- new_message = {"role": "assistant", "content": ""}
29
-
30
- for chunk in completion:
31
- if chunk.choices[0].delta.content:
32
- print(chunk.choices[0].delta.content, end="", flush=True)
33
- new_message["content"] += chunk.choices[0].delta.content
34
-
35
- history.append(new_message)
36
-
37
- print()
 
 
 
 
 
 
1
+ import random
2
  from openai import OpenAI
3
 
4
  # Point to the local server
 
10
 
11
  # Open the file in read mode
12
  with open('Model_Test_Issues_zh_en_jp.txt', 'r', encoding='utf-8') as file:
13
+ # Read all lines from the file
14
+ lines = file.readlines()
15
+
16
+ # Loop indefinitely
17
+ while True:
18
+ # Choose a random line from the file
19
+ line = random.choice(lines).strip()
20
+ print(line)
21
+
22
+ # Add the line as the user's content to the history
23
+ history.append({"role": "user", "content": line})
24
+
25
+ # Generate the response
26
+ completion = client.chat.completions.create(
27
+ model="mod/Repository",
28
+ messages=history,
29
+ temperature=0.7,
30
+ stream=True,
31
+ stop=["### Evaluation:","<|end_of_text|>","Translation:"]
32
+ )
33
+
34
+ new_message = {"role": "assistant", "content": ""}
35
+
36
+ for chunk in completion:
37
+ if chunk.choices[0].delta.content:
38
+ print(chunk.choices[0].delta.content, end="", flush=True)
39
+ new_message["content"] += chunk.choices[0].delta.content
40
+
41
+ history.append(new_message)
42
+
43
+ print()