Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

main.go 1.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  1. // Package main implements a promptfoo provider that uses OpenAI's API.
  2. // It demonstrates a simple implementation of the provider interface using
  3. // shared code from the core and pkg1 packages.
  4. package main
  5. import (
  6. "fmt"
  7. "github.com/promptfoo/promptfoo/examples/golang-provider/core"
  8. "github.com/promptfoo/promptfoo/examples/golang-provider/pkg1"
  9. )
  10. // client is the shared OpenAI client instance used for all requests.
  11. var client = core.NewClient()
  12. // CallApi is the provider's implementation of promptfoo's API interface.
  13. // It processes prompts with configurable reasoning effort and returns the model's response.
  14. //
  15. // The prompt parameter is the input text to send to the model.
  16. // The options parameter may contain a config map with a "reasoning_effort" key
  17. // that accepts "low", "medium", or "high" values.
  18. //
  19. // Returns a map containing the "output" key with the model's response,
  20. // or an error if the API call fails.
  21. var CallApi func(string, map[string]interface{}, map[string]interface{}) (map[string]interface{}, error)
  22. // handlePrompt processes a prompt with configurable reasoning effort.
  23. // It extracts the reasoning_effort from options (defaulting to pkg1's default)
  24. // and calls the OpenAI API through the core client.
  25. func handlePrompt(prompt string, options map[string]interface{}, ctx map[string]interface{}) (map[string]interface{}, error) {
  26. reasoningEffort := pkg1.GetDefaultReasoningEffort()
  27. if val, ok := options["config"].(map[string]interface{})["reasoning_effort"].(string); ok {
  28. reasoningEffort = val
  29. }
  30. output, err := client.CreateCompletion(prompt, reasoningEffort)
  31. if err != nil {
  32. return nil, fmt.Errorf("completion error: %v", err)
  33. }
  34. return map[string]interface{}{
  35. "output": output,
  36. }, nil
  37. }
  38. func init() {
  39. // Assign our implementation to the wrapper's CallApi function.
  40. // This makes it available to promptfoo for evaluation.
  41. CallApi = handlePrompt
  42. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...