Skip to content

Instantly share code, notes, and snippets.

@mberman84
Created November 10, 2023 16:17
Show Gist options
  • Save mberman84/a1291cfb08d0a37c3d439028f3bc5f26 to your computer and use it in GitHub Desktop.
Save mberman84/a1291cfb08d0a37c3d439028f3bc5f26 to your computer and use it in GitHub Desktop.
OpenChat Code
import requests
import json
import gradio as gr
url = "http://localhost:11434/api/generate"
headers = {
'Content-Type': 'application/json',
}
conversation_history = []
def generate_response(prompt):
conversation_history.append(prompt)
full_prompt = "\n".join(conversation_history)
data = {
"model": "mistral",
"stream": False,
"prompt": full_prompt,
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
response_text = response.text
data = json.loads(response_text)
actual_response = data["response"]
conversation_history.append(actual_response)
return actual_response
else:
print("Error:", response.status_code, response.text)
return None
iface = gr.Interface(
fn=generate_response,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
outputs="text"
)
iface.launch()
@bibop
Copy link

bibop commented Nov 20, 2023 via email

@hiddenkirby
Copy link

hiddenkirby commented Feb 1, 2024

@nulltermin8d, yea that's what I needed! thanks! I am using Python 3.10.8 and Gradio 4.16.0

@ali7887
Copy link

ali7887 commented May 16, 2024

i have this error message :
ollama run mistral
pulling manifest
Error: pull model manifest: 403:

Your client does not have permission to get URL /token from this server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment