https://promptfoo.dev/ logo
I'm looking at promptfoo. Can you check whether yo...
# ❓|questions
n
Ya, actually the entire yaml, see if i can use Python instead. Make a small example and share Please Update and let me know
prompts: - prompt1.txt tests: - vars: user_preferences: generate_vars.py input: generate_vars.py - assertions: - type: equals value: 15000 providers: - "openai:gpt-4o" You must provide at least 1 prompt why getting this
import json def get_var(var_names, prompt, other_vars): preferences = { "facilities": ["gym"], "locality": "South Goa", "location": "Goa", "number_of_adults": 2, "number_of_children": 1, "number_of_days": 3, "number_of_rooms": 1, "price_education_done": True } input_text = "looking for a hotel in Goa" output = {} # Check if 'user_preferences' is one of the requested variables if 'user_preferences' in var_names: output['user_preferences'] = json.dumps(preferences) # Check if 'input' is one of the requested variables if 'input' in var_names: output['input'] = input_text # Return error if no recognized variables were passed if not output: return {'error': f"Unknown variables: {var_names}"} return {'output': output}
my python file
@michaelmichaelmichael Please Help me
m
Hi @NoAimNoBrain What's inside prompts1.txt? In general you should start files with a file:// prefix
Copy code
prompts:
  - file://prompt1.txt
providers:
  - openai:gpt-4o
tests:
  
  - vars:
      user_preferences: file://generate_vars.py
      input: file://generate_vars.py
    assertions:
      type: equals
      value: 15000
Your error could be from prompts1.txt not containing prompts. If you are around now respond and I'll send you a zoom link
n
You are a travel agent estimating hotel prices in Goa. Your task is to output ONLY a single integer representing the estimated price per night in rupees. Do not include any explanations or additional text. Price ranges: Budget hotels: 10000, Mid-range hotels: 15000, Luxury hotels: 25000, Villas: 20000. Rules: 1. If user mentions a specific price or budget, use that exact number. 2. For villa requests, use 20000. 3. If 'budget hotel' is mentioned, use 10000. 4. For luxury indicators (spa, sea view, etc.), use 25000 unless rules 1-3 apply. 5. Adjust price by 10% based on user requests. 6. For generic requests, use 10000. 7. If the query isn't about hotels/pricing, use the price from user preferences. 8. If no price can be determined and price_education_done is True, use 15000. 9. If price_education_done is False, output 0. User: {{input}} User Preferences: {{user_preferences}} AI:
sure please share me zoom link
i really need help right now
n
will join in 1 min
import json def get_var(var_name, prompt, other_vars): # Define user preferences as a dictionary user_preferences = { "facilities": ["gym"], "locality": "South Goa", "location": "Goa", "number_of_adults": 2, "number_of_children": 1, "number_of_days": 3, "number_of_rooms": 1, "price_education_done": True } input_text = "looking for a hotel in Goa" # Prepare the output based on the requested variable output = {} if var_name == 'user_preferences': output['user_preferences'] = json.dumps(user_preferences) # Return as JSON string elif var_name == 'input': output['input'] = input_text # Return the input text else: return {'error': f"Unknown variable: {var_name}"} return output
m
For other people following along. The error was in the shape of the variables returned by get_var/ We improved the docs and added an extra type check: https://github.com/promptfoo/promptfoo/commit/0ecd31ea0f6dc5880ed6b97588ba372acd9b2dbe
2 Views