Spaces:
Sleeping
Sleeping
File size: 1,389 Bytes
2e51161 |
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 |
import google.generativeai as genai
import google.ai.generativelanguage as glm
import os
genai.configure(api_key='AIzaSyALFCivW9GP25mbxL3W7Fv6u7m2ZHVlC8w')
def fileWriter(filename, content):
with open(filename, 'w') as f:
f.write(content)
return filename
discription = input('Enter the description of the game: ')
model = genai.GenerativeModel(model_name='gemini-1.0-pro')
chat = model.start_chat()
newPrompt = chat.send_message(discription+' Add a filename too.')
fileWriterFunctionCall = {
'function_declarations': [
{
'name': 'fileWriter',
'description': 'Writes content to a file.',
'parameters': {
'type_': 'OBJECT',
'properties': {
'filename': {'type_': 'STRING'},
'content': {'type_': 'STRING'}
},
'required': ['filename', 'content']
}
}
]
}
model = genai.GenerativeModel(model_name='gemini-1.0-pro', tools=fileWriterFunctionCall)
chat = model.start_chat()
response = chat.send_message(discription+' Add a filename too.\n\n' + newPrompt.text)
fc = response.candidates[0].content.parts[0].function_call
assert fc.name == 'fileWriter'
filename = fc.args['filename']
content = fc.args['content']
result = fileWriter(filename, content)
|