MarkChen1214 commited on
Commit
e11e4a6
·
1 Parent(s): 297c9ff

chore: Refactor chat_with_openai function to improve readability and maintainability

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -44,12 +44,13 @@ HEADERS = {
44
  MAX_SEC = 30
45
  MAX_INPUT_LENGTH = 5000
46
 
47
- client = OpenAI(
48
- base_url=API_URL,
49
- api_key=TOKEN
50
- )
51
 
52
- def chat_with_openai(client, model_name, system_message, user_message, temperature=0.5, max_tokens=1024, top_p=0.5):
 
 
 
 
 
53
  chat_completion = client.chat.completions.create(
54
  model=model_name,
55
  messages=[
@@ -163,7 +164,6 @@ with gr.Blocks() as demo:
163
  yield history
164
  else:
165
  r = chat_with_openai(
166
- client,
167
  MODEL_NAME,
168
  system_prompt,
169
  history[-1][0],
 
44
  MAX_SEC = 30
45
  MAX_INPUT_LENGTH = 5000
46
 
 
 
 
 
47
 
48
+ def chat_with_openai(model_name, system_message, user_message, temperature=0.5, max_tokens=1024, top_p=0.5):
49
+ client = OpenAI(
50
+ base_url=API_URL,
51
+ api_key=TOKEN
52
+ )
53
+
54
  chat_completion = client.chat.completions.create(
55
  model=model_name,
56
  messages=[
 
164
  yield history
165
  else:
166
  r = chat_with_openai(
 
167
  MODEL_NAME,
168
  system_prompt,
169
  history[-1][0],