elshehawy commited on
Commit
a091e6a
·
1 Parent(s): d3f1a70

Update get_completion method with the new openai api

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -4,15 +4,19 @@ import os
4
 
5
 
6
  llm_model = 'gpt-3.5-turbo-0125'
7
- openai.api_key = os.environ['OPENAI_API_KEY']
 
 
 
 
8
 
9
 
10
  def get_completion(prompt, model=llm_model):
11
  messages = [{"role": "user", "content": prompt}]
12
- response = openai.ChatCompletion.create(
13
- model=model,
14
  messages=messages,
15
- temperature=0,
 
16
  )
17
  return response.choices[0].message["content"]
18
 
@@ -28,5 +32,9 @@ def find_orgs(sentence):
28
  """
29
  return get_completion(prompt)
30
 
31
- iface = gr.Interface(fn=find_orgs, inputs="text", outputs="text")
 
 
 
 
32
  iface.launch(share=True)
 
4
 
5
 
6
  llm_model = 'gpt-3.5-turbo-0125'
7
+ # openai.api_key = os.environ['OPENAI_API_KEY']
8
+
9
+ client = OpenAI(
10
+ api_key=os.environ.get("OPENAI_API_KEY"),
11
+ )
12
 
13
 
14
  def get_completion(prompt, model=llm_model):
15
  messages = [{"role": "user", "content": prompt}]
16
+ response = client.chat.completions.create(
 
17
  messages=messages,
18
+ model=model,
19
+ temperature=0,
20
  )
21
  return response.choices[0].message["content"]
22
 
 
32
  """
33
  return get_completion(prompt)
34
 
35
+ example = """
36
+
37
+
38
+ """
39
+ iface = gr.Interface(fn=find_orgs, inputs="text", outputs="text", examples=[[example]])
40
  iface.launch(share=True)