Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
""
|
| 7 |
-
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def respond(
|
| 11 |
message,
|
|
@@ -25,20 +29,15 @@ def respond(
|
|
| 25 |
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
|
| 28 |
-
response =
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
temperature=temperature,
|
| 35 |
top_p=top_p,
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
|
|
|
|
| 42 |
|
| 43 |
"""
|
| 44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
|
| 4 |
+
# Initialize OpenAI client
|
| 5 |
+
token = "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"
|
| 6 |
+
endpoint = "https://models.github.ai/inference"
|
| 7 |
+
model = "openai/gpt-4.1"
|
| 8 |
|
| 9 |
+
client = OpenAI(
|
| 10 |
+
base_url=endpoint,
|
| 11 |
+
api_key=token,
|
| 12 |
+
)
|
| 13 |
|
| 14 |
def respond(
|
| 15 |
message,
|
|
|
|
| 29 |
|
| 30 |
messages.append({"role": "user", "content": message})
|
| 31 |
|
| 32 |
+
response = client.chat.completions.create(
|
| 33 |
+
messages=messages,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
temperature=temperature,
|
| 35 |
top_p=top_p,
|
| 36 |
+
model=model,
|
| 37 |
+
max_tokens=max_tokens
|
| 38 |
+
)
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
return response.choices[0].message.content
|
| 41 |
|
| 42 |
"""
|
| 43 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|