Spaces:
Sleeping
Sleeping
File size: 772 Bytes
66ff3e9 |
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 |
import gradio as gr
import requests
def chat_with_openrouter(prompt):
url = "https://api.openrouter.ai/v1/chat/completions"
headers = {"Authorization": "Bearer OpenRounter_API_KEY"}
data = {
"model": "openai/gpt-4o-mini-2024-07-18",
"messages": [{"role": "user", "content": prompt}],
"top_p:" 1,
"temperature:" 1,
"repetition_penalty:" 1,
"transforms": []
}
response = requests.post(url, headers=headers, json=data)
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response")
iface = gr.Interface(
fn=chat_with_openrouter,
inputs=gr.Textbox(lines=2, placeholder="Ask me anything"),
outputs="text",
title="Chat with OpenRouter",
)
iface.launch()
|