Last active
January 8, 2024 02:47
-
-
Save appvoid/6469f2866cfd7ae2dec68ff56da208f7 to your computer and use it in GitHub Desktop.
custom gpts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gpt | |
while 1: | |
prompt = gpt.examples([ | |
("Earth is plain", "false"), | |
("Information is data", "relative"), | |
("My hair is black", "relative"), | |
("Google is a plant", "false"), | |
("God is good", "true"), | |
], input('> ')) | |
output = gpt.complete('This is a truth-seeker AI. It answers true, false or relative based on real facts. Doesnt have sensors so answers should be relative for real-time information or data.\n'+prompt, n=512) | |
print(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from requests import post | |
url = "http://localhost:1234/v1/completions" | |
stop_word = ['||'] | |
def examples(examples, query, stop='||'): | |
global stop_word | |
stop_word = [stop] | |
# Join examples with the stop word and format them | |
examples_formatted = "\n\n".join([f'Input: {example}\nOutput: {translation} {stop}' for example, translation in examples]) | |
# Create the final prompt by combining examples and the query | |
prompt = f"{examples_formatted}\n\nInput: {query}\nOutput:" | |
return prompt | |
def complete (prompt, n=64, temp=0.1, stop=stop_word, data=False): | |
data = { | |
"prompt": prompt, | |
"temperature": temp, | |
"max_tokens": n, | |
"stream": False, | |
"stop": stop | |
} | |
response = post( | |
url, | |
headers={ "Content-Type": "application/json"}, | |
json=data | |
) | |
if response.status_code == 200: | |
if (data==True): | |
return response.json() | |
else: | |
return response.json()['choices'][0]['text'] | |
else: | |
print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment