Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,40 @@
|
|
1 |
import os
|
|
|
2 |
from langchain_ai21 import ChatAI21
|
3 |
-
from
|
4 |
-
from
|
5 |
-
|
6 |
-
# 1. Set up your AI21 API key
|
7 |
-
os.environ["AI21_API_KEY"] = "your-ai21-api-key"
|
8 |
-
|
9 |
-
# 2. Create a prompt template for the chatbot
|
10 |
-
prompt = PromptTemplate(
|
11 |
-
input_variables=["user_input"],
|
12 |
-
template="""
|
13 |
-
You are a helpful and friendly chatbot. Respond concisely and informatively.
|
14 |
-
|
15 |
-
User: {user_input}
|
16 |
-
Chatbot:
|
17 |
-
"""
|
18 |
-
)
|
19 |
-
llm = ChatAI21(model="jamba-instruct", temperature=0)
|
20 |
-
|
21 |
-
from langchain.memory import ConversationBufferMemory
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
import gradio as gr
|
29 |
|
|
|
30 |
def chatbot_response(user_input):
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
fn=chatbot_response,
|
35 |
inputs="text",
|
36 |
outputs="text",
|
37 |
-
title="
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import gradio as gr
|
3 |
from langchain_ai21 import ChatAI21
|
4 |
+
from ai21 import AI21Client
|
5 |
+
from ai21.models.chat import ChatMessage, DocumentSchema
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Set your AI21 API key
|
8 |
+
os.environ["AI21_API_KEY"] = "8T6NvXgGjhtlh9bh65jsNqb584BOorNM"
|
9 |
+
client = AI21Client(api_key="8T6NvXgGjhtlh9bh65jsNqb584BOorNM")
|
10 |
+
# Initialize the Jamba model
|
11 |
+
chatbot = ChatAI21(model="jamba-instruct", temperature=0.7)
|
|
|
12 |
|
13 |
+
# Define the function to handle chat
|
14 |
def chatbot_response(user_input):
|
15 |
+
# Wrap input into a dictionary with the expected format
|
16 |
+
messages = [ChatMessage(role='system', content='You are a concise factual based question answering assistant.'),
|
17 |
+
ChatMessage(role='user', content=user_input)
|
18 |
+
]
|
19 |
+
response = client.chat.completions.create(messages=messages,
|
20 |
+
model='jamba-1.5-large',
|
21 |
+
# max_tokens=4096,
|
22 |
+
# temperature=0.4,
|
23 |
+
# top_p=1.0,
|
24 |
+
# stop = [], ## ['####', '\n'],
|
25 |
+
# n=1,
|
26 |
+
# stream = False
|
27 |
+
)
|
28 |
+
return response.choices[0].message.content
|
29 |
+
# Create the Gradio interface
|
30 |
+
interface = gr.Interface(
|
31 |
fn=chatbot_response,
|
32 |
inputs="text",
|
33 |
outputs="text",
|
34 |
+
title="Jamba Chatbot",
|
35 |
+
description="A simple chatbot using AI21 Labs' Jamba technology."
|
36 |
+
)
|
37 |
+
|
38 |
+
# Launch the Gradio app
|
39 |
+
if __name__ == "__main__":
|
40 |
+
interface.launch()
|