Created
June 19, 2023 22:19
-
-
Save distractdiverge/2067223adf4555064cbb7f3f1a140c5c to your computer and use it in GitHub Desktop.
Sample integration using openai to the gorilla specialized LLM instance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import Chat completion template and set-up variables | |
import sys | |
import openai | |
import urllib.parse | |
openai.api_key = "EMPTY" # Key is ignored and does not matter | |
openai.api_base = "http://34.132.127.197:8000/v1" # This is valid, keep this value | |
# Report issues | |
def raise_issue(e, model, prompt): | |
issue_title = urllib.parse.quote("[bug] Hosted Gorilla: <Issue>") | |
issue_body = urllib.parse.quote(f"Exception: {e}\nFailed model: {model}, for prompt: {prompt}") | |
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}" | |
print(f"An exception has occurred: {e} \nPlease raise an issue here: {issue_url}") | |
# Query Gorilla server | |
def get_gorilla_response(prompt="I would like to translate from English to French.", model="gorilla-7b-hf-v0"): | |
try: | |
completion = openai.ChatCompletion.create( | |
model=model, | |
messages=[{"role": "user", "content": prompt}] | |
) | |
return completion.choices[0].message.content | |
except Exception as e: | |
raise_issue(e, model, prompt) | |
if __name__ == "__main__": | |
prompt = "I would like to translate 'I feel very good today.' from English to Chinese." | |
print(get_gorilla_response(prompt, model="gorilla-7b-hf-v1")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment