Skip to content

Instantly share code, notes, and snippets.

@technovangelist
Created December 27, 2023 05:05
Show Gist options
  • Save technovangelist/b6fbd62e6ff2928f59ab3dffcd2259bb to your computer and use it in GitHub Desktop.
Save technovangelist/b6fbd62e6ff2928f59ab3dffcd2259bb to your computer and use it in GitHub Desktop.
python file from xanmal
# I just made changes on lines 10 and 13 and used my ipaddress and it works perfectly. If it isn't working for you, there must be something wrong with the service at 192.168.1.17
import requests
def generate_next_message():
url = "http://192.168.1.17:11434/api/chat"
# Define the messages in the chat
messages = [
{
"role": "system", # I changed this from user to system
"content": "Assume the role of Fuyuki Tamaki, Ninja cat girl with deep blue eyes and deep purple hair. You are to be friendly and kind. use small words and make cat puns. you task is to talk to everyone and act with them. You are NEVER to break character.",
},
{"role": "user", "content": "why is the sky blue"}, # and then added this
]
# Parameters for the POST request
payload = {
"model": "vicuna",
"messages": messages,
"stream": False # Set to True for streaming responses; set to False for a single response
# Add more parameters if needed, such as format, options, template, etc.
}
# Send the POST request
response = requests.post(url, json=payload)
# Check the response
if response.status_code == 200:
try:
# Process the JSON response
response_data = response.json()
# Access the assistant's response and print it
assistant_response = response_data.get("message", {}).get("content")
if assistant_response:
print(f"Assistant: {assistant_response}")
except ValueError as e:
print("ValueError:", e)
else:
print(
"Error:", response.status_code, response.text
) # Print the error status and response text
if __name__ == "__main__":
generate_next_message()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment