Spaces:
Sleeping
Sleeping
import gradio as gr | |
from openai import OpenAI | |
BASE_URL = "https://kks679fhv1td67-8000.proxy.runpod.net/v1" | |
API_KEY="SOMEHOW" | |
# Create an OpenAI client to interact with the API server | |
client = OpenAI( | |
base_url=BASE_URL, | |
api_key=API_KEY | |
) | |
def predict(message, history): | |
# Convert chat history to OpenAI format | |
history_openai_format = [{ | |
"role": "system", | |
"content": "Tu es un excellent assistant IA nommé Adia, développé par CONCREE pour accompagner les entrepreneurs Africains." | |
}] | |
for human, assistant in history: | |
history_openai_format.append({"role": "user", "content": human}) | |
history_openai_format.append({ | |
"role": "assistant", | |
"content": assistant | |
}) | |
history_openai_format.append({"role": "user", "content": message}) | |
# Create a chat completion request and send it to the API server | |
stream = client.chat.completions.create( | |
model="CONCREE/meta-adia-llm-instruct", # Model name to use | |
messages=history_openai_format, # Chat history | |
temperature=0.1, # Temperature for text generation | |
stream=True, # Stream response | |
) | |
# Read and return generated text from response stream | |
partial_message = "" | |
for chunk in stream: | |
partial_message += (chunk.choices[0].delta.content or "") | |
yield partial_message | |
# Create and launch a chat interface with Gradio | |
gr.ChatInterface(predict).queue().launch() |