Spaces:
Running
Running
Simplified
Browse files- gen_api_answer.py +31 -0
gen_api_answer.py
CHANGED
@@ -9,6 +9,37 @@ anthropic_client = anthropic.Anthropic()
|
|
9 |
openai_client = OpenAI()
|
10 |
together_client = Together()
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
SYSTEM_PROMPT = """Please act as an impartial judge and evaluate based on the user's instruction. Your output format should strictly adhere to JSON as follows: {"feedback": "<write feedback>", "result": <numerical score>}. Ensure the output is valid JSON, without additional formatting or explanations."""
|
13 |
|
14 |
|
|
|
9 |
openai_client = OpenAI()
|
10 |
together_client = Together()
|
11 |
|
12 |
+
# Initialize OpenAI client
|
13 |
+
|
14 |
+
EXAMPLE_GENERATION_PROMPT_SYSTEM = """You are an assistant that generates random conversations between a human and an AI assistant for testing purposes."""
|
15 |
+
EXAMPLE_GENERATION_PROMPT_USER = """Please provide a random human message and an appropriate AI response in the format of an academic benchmark dataset e.g.,. User: "Hi, I'm trying to solve a crossword puzzle, but I've never done one of these before. Can you help me out?" / AI Response: "Absolutely! I'd be delighted to help you with your crossword puzzle. Just tell me the clues and the number of letters needed for each answer (and any letters you may have already filled in), and I'll do my best to help you find the solutions. If you have any specific questions about how to approach solving crossword puzzles in general, feel free to ask those as well!". Format the output as JSON:\n\n{\"human\": \"<human message>\", \"ai\": \"<AI assistant response>\"}"""
|
16 |
+
|
17 |
+
def get_random_human_ai_pair():
|
18 |
+
# Use GPT-3.5 to generate a random conversation
|
19 |
+
completion = openai_client.chat.completions.create(
|
20 |
+
model="gpt-3.5-turbo",
|
21 |
+
messages=[
|
22 |
+
{"role": "system", "content": EXAMPLE_GENERATION_PROMPT_SYSTEM},
|
23 |
+
{"role": "user", "content": EXAMPLE_GENERATION_PROMPT_USER},
|
24 |
+
],
|
25 |
+
max_completion_tokens=300,
|
26 |
+
temperature=1,
|
27 |
+
)
|
28 |
+
|
29 |
+
# Parse the response to get the human input and AI response
|
30 |
+
raw_response = completion.choices[0].message.content.strip()
|
31 |
+
|
32 |
+
try:
|
33 |
+
data = json.loads(raw_response)
|
34 |
+
human_message = data.get("human", "Hello, how are you?")
|
35 |
+
ai_message = data.get("ai", "I'm doing well, thank you!")
|
36 |
+
except json.JSONDecodeError:
|
37 |
+
# If parsing fails, set default messages
|
38 |
+
human_message = "Hello, how are you?"
|
39 |
+
ai_message = "I'm doing well, thank you!"
|
40 |
+
|
41 |
+
return human_message, ai_message
|
42 |
+
|
43 |
SYSTEM_PROMPT = """Please act as an impartial judge and evaluate based on the user's instruction. Your output format should strictly adhere to JSON as follows: {"feedback": "<write feedback>", "result": <numerical score>}. Ensure the output is valid JSON, without additional formatting or explanations."""
|
44 |
|
45 |
|