-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GPT-3 and Llama 2 7B chatbot functionality
- Loading branch information
Mark Chen
authored and
Mark Chen
committed
Feb 7, 2024
1 parent
e2be12d
commit 4e1ab80
Showing
2 changed files
with
40 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
import gradio as gr | ||
import requests | ||
|
||
def echo(message, history): | ||
is_gpt3 = False | ||
|
||
|
||
def echo_gptchatbot(message, history): | ||
# Post the message to the server | ||
response = requests.post( | ||
"http://127.0.0.1:8000/api/chat/gpt3", data={"user_request": message} | ||
) | ||
# Return the response | ||
llm_output = response.json()["result"]["content"] | ||
|
||
return llm_output | ||
|
||
|
||
def echo_llamachatbot(message, history): | ||
# Post the message to the server | ||
response = requests.post("http://127.0.0.1:8000/api/chat/gpt3", data={"user_request": message}) | ||
response = requests.post( | ||
"http://127.0.0.1:8000/api/chat/llama", data={"user_request": message} | ||
) | ||
|
||
# Return the response | ||
llm_output = response.json()["result"]['content'] | ||
llm_output = response.json()["result"][0]["generated_text"] | ||
|
||
return llm_output | ||
|
||
demo = gr.ChatInterface(fn=echo, examples=["What is OpenAI?", "What is LLM?"], title="LLM Chatbot") | ||
|
||
demo.launch() | ||
|
||
# Create a Gradio interface with the chatbot | ||
if is_gpt3: | ||
demo = gr.ChatInterface( | ||
fn=echo_gptchatbot, | ||
examples=["What is OpenAI?", "What is GPT-3?"], | ||
title="GPT-3 Chatbot", | ||
) | ||
else: | ||
demo = gr.ChatInterface( | ||
fn=echo_llamachatbot, | ||
examples=["What is OpenAI?", "What is LLM?"], | ||
title="LLM Chatbot - Llama 2 7B", | ||
) | ||
|
||
demo.launch() |
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