Spaces:
Runtime error
Runtime error
File size: 6,323 Bytes
1d03d1e | 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | import datetime
from google import genai
from google.genai import models, types
import json
# Define the function declaration for the model
meeting_function = {
"name": "book_a_meeting",
"description": "Books a meeting with the specified details.",
"parameters": {
"type": "object",
"properties": {
"date": {
"type": "string",
"description": "The date of the meeting",
},
"time": {
"type": "string",
"description": "The time of the meeting, e.g. 14:00",
},
"topic": {
"type": "string",
"description": "The topic of the meeting, e.g. Project Update",
},
},
"required": ["date", "time", "topic"],
},
}
generate_quizzes_on_document_function = {
"name": "generate_quizzes_on_document",
"description": "Generates quizzes based on the provided document.",
"parameters": {
"type": "object",
"properties": {
"notes": {
"type": "string",
"description": "The date of the meeting",
},
},
"required": ["notes"],
},
}
quiz_response_format = """
[
{
"quiz_id": "none",
"question_text": "What is the primary focus of biology?",
"question_type": "multiple_choice",
"answers": [
{"option_text": "The study of inanimate objects", "is_correct": false},
{"option_text": "The scientific study of life and living organisms", "is_correct": true},
{"option_text": "The study of celestial bodies", "is_correct": false}
]
},
{
"quiz_id": "none",
"question_text": "Which of the following is a fundamental theme of biology?",
"question_type": "multiple_choice",
"answers": [
{"option_text": "The cell as the basic unit of life", "is_correct": true},
{"option_text": "The study of weather patterns", "is_correct": false},
{"option_text": "The analysis of financial markets", "is_correct": false}
]
}
]
"""
def create_prompt(user_input: str) -> str:
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
return f"Today is {current_date}. {user_input}"
def create_document_summarize_prompt(document: str) -> str:
return f"""Summarize the following document with BlockNote schema. Here is the BlockNote schema format:
[
{{
type: "paragraph",
content: "Welcome to this demo!",
}},
{{
type: "paragraph",
}},
{{
type: "paragraph",
content: [
{{
type: "text",
text: "Blocks:",
styles: {{ bold: true }},
}},
],
}},
{{
type: "paragraph",
content: "Paragraph",
}},
{{
type: "heading",
content: "Heading",
}},
{{
id: "toggle-heading",
type: "heading",
props: {{ isToggleable: true }},
content: "Toggle Heading",
}},
{{
type: "quote",
content: "Quote",
}},
{{
type: "bulletListItem",
content: "Bullet List Item",
}},
{{
type: "numberedListItem",
content: "Numbered List Item",
}},
{{
type: "checkListItem",
content: "Check List Item",
}},
{{
id: "toggle-list-item",
type: "toggleListItem",
content: "Toggle List Item",
}},
{{
type: "codeBlock",
props: {{ language: "javascript" }},
content: "console.log('Hello, world!');",
}},
{{
type: "table",
content: {{
type: "tableContent",
rows: [
{{
cells: ["Table Cell", "Table Cell", "Table Cell"],
}},
{{
cells: ["Table Cell", "Table Cell", "Table Cell"],
}},
{{
cells: ["Table Cell", "Table Cell", "Table Cell"],
}},
],
}},
}},
{{
type: "file",
}},
{{
type: "image",
props: {{
url: "https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg",
caption: "From https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg",
}},
}},
{{
type: "video",
props: {{
url: "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm",
caption: "From https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm",
}},
}},
{{
type: "audio",
props: {{
url: "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
caption: "From https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
}},
}},
{{
type: "paragraph",
}},
{{
type: "paragraph",
content: [
{{
type: "text",
text: "Inline Content:",
styles: {{ bold: true }},
}},
],
}},
{{
type: "paragraph",
content: [
{{
type: "text",
text: "Styled Text",
styles: {{
bold: true,
italic: true,
textColor: "red",
backgroundColor: "blue",
}},
}},
{{
type: "text",
text: " ",
styles: {{}},
}},
{{
type: "link",
content: "Link",
href: "https://www.blocknotejs.org",
}},
],
}},
{{
type: "paragraph",
}},
]
{document}"""
def create_quizzes_on_notes_prompt(notes: str, response_format: str) -> str:
prompt = f"""Generate quizzes based on this content as JSON format. Here is the example response:
{quiz_response_format}
Here is the content: {notes}"""
return prompt
def book_a_meeting(date: str, time: str, topic: str) -> str:
result = {
"status": "success",
"meeting": {"date": date, "time": time, "topic": topic},
}
res = json.dumps(result)
print(res)
return res
|