| import os |
| import gradio as gr |
| from langchain_ai21 import ChatAI21 |
| from ai21 import AI21Client |
| from ai21.models.chat import ChatMessage, DocumentSchema |
|
|
| |
| os.environ["AI21_API_KEY"] = "8T6NvXgGjhtlh9bh65jsNqb584BOorNM" |
| client = AI21Client(api_key="8T6NvXgGjhtlh9bh65jsNqb584BOorNM") |
| |
| chatbot = ChatAI21(model="jamba-instruct", temperature=0.7) |
|
|
| |
| def chatbot_response(user_input): |
| |
| messages = [ChatMessage(role='system', content='You are a concise factual based question answering assistant.'), |
| ChatMessage(role='user', content=user_input) |
| ] |
| response = client.chat.completions.create(messages=messages, |
| model='jamba-1.5-large', |
| |
| |
| |
| |
| |
| |
| ) |
| return response.choices[0].message.content |
| |
| interface = gr.Interface( |
| fn=chatbot_response, |
| inputs="text", |
| outputs="text", |
| title="Jamba Chatbot", |
| description="A simple chatbot using AI21 Labs' Jamba technology." |
| ) |
|
|
| |
| if __name__ == "__main__": |
| interface.launch() |