File size: 1,465 Bytes
75ac6fe
46a3c34
 
 
 
 
 
 
 
 
75ac6fe
 
46a3c34
de9b5da
46a3c34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de9b5da
 
46a3c34
 
 
 
de9b5da
 
 
46a3c34
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()