Spaces:
Runtime error
Runtime error
Update get_completion method with the new openai api
Browse files
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 =
|
13 |
-
model=model,
|
14 |
messages=messages,
|
15 |
-
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
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)
|