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

provider.py 1.2 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
  1. from openai import AsyncOpenAI, OpenAI
  2. async_client = AsyncOpenAI()
  3. client = OpenAI()
  4. def call_api(prompt, options, context):
  5. # Get config values
  6. # some_option = options.get("config").get("someOption")
  7. chat_completion = client.chat.completions.create(
  8. messages=[
  9. {
  10. "role": "system",
  11. "content": "You are a marketer working for a startup called Bananamax.",
  12. },
  13. {
  14. "role": "user",
  15. "content": prompt,
  16. },
  17. ],
  18. model="gpt-4o-mini",
  19. )
  20. return {"output": chat_completion.choices[0].message.content}
  21. def some_other_function(prompt, options, context):
  22. return call_api(prompt + "\nWrite in ALL CAPS", options, context)
  23. async def async_provider(prompt, options, context):
  24. chat_completion = await async_client.chat.completions.create(
  25. messages=[
  26. {
  27. "role": "system",
  28. "content": "You are a marketer working for a startup called Bananamax.",
  29. },
  30. {
  31. "role": "user",
  32. "content": prompt,
  33. },
  34. ],
  35. model="gpt-4o",
  36. )
  37. return {"output": chat_completion.choices[0].message.content}
Tip!

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

Comments

Loading...