Spaces:
Build error
Build error
Commit ·
0e30d13
1
Parent(s): fe56beb
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import urllib.parse
|
| 3 |
+
|
| 4 |
+
openai.api_key = "EMPTY" # Key is ignored and does not matter
|
| 5 |
+
openai.api_base = "http://zanino.millennium.berkeley.edu:8000/v1"
|
| 6 |
+
# Alternate mirrors
|
| 7 |
+
# openai.api_base = "http://34.132.127.197:8000/v1"
|
| 8 |
+
|
| 9 |
+
# Report issues
|
| 10 |
+
def raise_issue(e, model, prompt):
|
| 11 |
+
issue_title = urllib.parse.quote("[bug] Hosted Gorilla: <Issue>")
|
| 12 |
+
issue_body = urllib.parse.quote(f"Exception: {e}\nFailed model: {model}, for prompt: {prompt}")
|
| 13 |
+
issue_url = f"https://github.com/ShishirPatil/gorilla/issues/new?assignees=&labels=hosted-gorilla&projects=&template=hosted-gorilla-.md&title={issue_title}&body={issue_body}"
|
| 14 |
+
print(f"An exception has occurred: {e} \nPlease raise an issue here: {issue_url}")
|
| 15 |
+
|
| 16 |
+
# Query Gorilla server
|
| 17 |
+
def get_gorilla_response(prompt="I would like to translate from English to French.", model="gorilla-7b-hf-v1"):
|
| 18 |
+
try:
|
| 19 |
+
completion = openai.ChatCompletion.create(
|
| 20 |
+
model=model,
|
| 21 |
+
messages=[{"role": "user", "content": prompt}]
|
| 22 |
+
)
|
| 23 |
+
return completion.choices[0].message.content
|
| 24 |
+
except Exception as e:
|
| 25 |
+
raise_issue(e, model, prompt)
|
| 26 |
+
|
| 27 |
+
import gradio as gr
|
| 28 |
+
|
| 29 |
+
def generate_algo(problem):
|
| 30 |
+
response = get_gorilla_response(prompt, model="gorilla-7b-hf-v1")
|
| 31 |
+
return response
|
| 32 |
+
|
| 33 |
+
bot = gr.Interface(fn=generate_algo, inputs="text", outputs="text", title="Ask Grodd: API Query Assistant",
|
| 34 |
+
description="Empower your LLM with Grodd's API guidance for 1,600+ integrations")
|
| 35 |
+
|
| 36 |
+
bot.launch()
|