Spaces:
Running
Running
File size: 3,142 Bytes
09ed935 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
from typing import Literal
import json
type VoiceName = Literal["Aoede", "Charon", "Fenrir", "Kore", "Puck"]
type GeminiModel = Literal["gemini-2.0-flash-exp"]
_TOOL_DEFINITIONS = {
"functionDeclarations": [
{
"name": "get_clue",
"description": "Gets the clue from the board which returns the clue and answer",
"parameters": {
"type": "object",
"properties": {
"category_index": {"type": "integer", "description": "Index of selected category."},
"dollar_index": {"type": "integer", "description": "Index of selected dollar amount."},
},
"required": ["category_index", "dollar_index"],
},
},
{
"name": "update_score",
"description": "Updates whether user got the question correct or not.",
"parameters": {
"type": "object",
"properties": {
"is_correct": {"type": "boolean", "description": "True if correct. False is incorrect."},
},
"required": ["is_correct"],
},
},
]
}
_SYSTEM_INSTRUCTIONS = """
You are the host of Jeopardy. Make sure users follow the rules of the game.
You have access to the following tools:
- get_clue: Gets the clue selected by the user. Always use this for picking clues. Do not make up your own clues.
- update_score: Updates the users score depending on if they answered the clue correctly.
The categories are [[categories]]. Each category has 5 questions, with the following dollar
amounts: $200, $400, $600, $800, $1000.
When the user asks for a clue, they will specify the category and dollar amount. Use the
`get_clue` tool by passing in the corresponding indexes for the category and dollar
amount.
For example if the categories are Witches, Gold Rush, American History, Desserts, Wet & Wild,
and the user says "American History for $800", the index will be 2 for the category and 3
for the dollar amount.
The `get_clue` tool will return the clue and answer if it is valid. If it is invalid it
will return an error message.
Wait for the `get_clue` tool response before responding.
When you get the response to the `get_clue` tool, read the clue to the user.
Briefly explain to the user why their answer is correct or wrong.
Use the `update_score` tool to update their score. Pass in true if they were correct.
Pass in false if they were not correct. This tool will return the user's current score.
""".strip()
def make_system_instruction(categories: list[str]):
return _SYSTEM_INSTRUCTIONS.replace("[[categories]]", ", ".join(categories))
def make_gemini_live_api_config(
model: GeminiModel = "gemini-2.0-flash-exp",
system_instructions: str = "",
voice_name: VoiceName = "Puck",
):
return json.dumps(
{
"setup": {
"model": f"models/{model}",
"system_instruction": {"role": "user", "parts": [{"text": system_instructions}]},
"tools": _TOOL_DEFINITIONS,
"generation_config": {
"temperature": 0.3,
"response_modalities": ["audio"],
"speech_config": {"voice_config": {"prebuilt_voice_config": {"voice_name": voice_name}}},
},
}
}
)
|