-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #776 from Mirascope/add-provider-google
feat: Add provider Google
- Loading branch information
Showing
284 changed files
with
8,812 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mirascope.core.google.call | ||
|
||
::: mirascope.core.google.call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mirascope.core.google.call_params | ||
|
||
::: mirascope.core.google.call_params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mirascope.core.google.call_response | ||
|
||
::: mirascope.core.google.call_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mirascope.core.google.call_response_chunk | ||
|
||
::: mirascope.core.google.call_response_chunk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mirascope.core.google.dynamic_config | ||
|
||
::: mirascope.core.google.dynamic_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mirascope.core.google.stream | ||
|
||
::: mirascope.core.google.stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mirascope.core.google.tool | ||
|
||
::: mirascope.core.google.tool |
50 changes: 50 additions & 0 deletions
50
examples/learn/agents/human_in_the_loop/google/base_message_param.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from mirascope.core import BaseDynamicConfig, BaseMessageParam, google | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
def _ask_for_help(self, question: str) -> str: | ||
"""Asks for help from an expert.""" | ||
print("[Assistant Needs Help]") | ||
print(f"[QUESTION]: {question}") | ||
answer = input("[ANSWER]: ") | ||
print("[End Help]") | ||
return answer | ||
|
||
@google.call("gemini-1.5-flash") | ||
def _call(self, query: str) -> BaseDynamicConfig: | ||
messages = [ | ||
BaseMessageParam(role="system", content="You are a librarian"), | ||
*self.history, | ||
BaseMessageParam(role="user", content=query), | ||
] | ||
return {"messages": messages, "tools": [self._ask_for_help]} | ||
|
||
def _step(self, query: str) -> str: | ||
if query: | ||
self.history.append(BaseMessageParam(role="user", content=query)) | ||
response = self._call(query) | ||
self.history.append(response.message_param) | ||
tools_and_outputs = [] | ||
if tools := response.tools: | ||
for tool in tools: | ||
print(f"[Calling Tool '{tool._name()}' with args {tool.args}]") | ||
tools_and_outputs.append((tool, tool.call())) | ||
self.history += response.tool_message_params(tools_and_outputs) | ||
return self._step("") | ||
else: | ||
return response.content | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
step_output = self._step(query) | ||
print(step_output) | ||
|
||
|
||
Librarian().run() |
50 changes: 50 additions & 0 deletions
50
examples/learn/agents/human_in_the_loop/google/messages.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from mirascope.core import BaseDynamicConfig, Messages, google | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
def _ask_for_help(self, question: str) -> str: | ||
"""Asks for help from an expert.""" | ||
print("[Assistant Needs Help]") | ||
print(f"[QUESTION]: {question}") | ||
answer = input("[ANSWER]: ") | ||
print("[End Help]") | ||
return answer | ||
|
||
@google.call("gemini-1.5-flash") | ||
def _call(self, query: str) -> BaseDynamicConfig: | ||
messages = [ | ||
Messages.System("You are a librarian"), | ||
*self.history, | ||
Messages.User(query), | ||
] | ||
return {"messages": messages, "tools": [self._ask_for_help]} | ||
|
||
def _step(self, query: str) -> str: | ||
if query: | ||
self.history.append(Messages.User(query)) | ||
response = self._call(query) | ||
self.history.append(response.message_param) | ||
tools_and_outputs = [] | ||
if tools := response.tools: | ||
for tool in tools: | ||
print(f"[Calling Tool '{tool._name()}' with args {tool.args}]") | ||
tools_and_outputs.append((tool, tool.call())) | ||
self.history += response.tool_message_params(tools_and_outputs) | ||
return self._step("") | ||
else: | ||
return response.content | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
step_output = self._step(query) | ||
print(step_output) | ||
|
||
|
||
Librarian().run() |
50 changes: 50 additions & 0 deletions
50
examples/learn/agents/human_in_the_loop/google/shorthand.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from mirascope.core import BaseDynamicConfig, Messages, google | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
def _ask_for_help(self, question: str) -> str: | ||
"""Asks for help from an expert.""" | ||
print("[Assistant Needs Help]") | ||
print(f"[QUESTION]: {question}") | ||
answer = input("[ANSWER]: ") | ||
print("[End Help]") | ||
return answer | ||
|
||
@google.call("gemini-1.5-flash") | ||
def _call(self, query: str) -> BaseDynamicConfig: | ||
messages = [ | ||
Messages.System("You are a librarian"), | ||
*self.history, | ||
Messages.User(query), | ||
] | ||
return {"messages": messages, "tools": [self._ask_for_help]} | ||
|
||
def _step(self, query: str) -> str: | ||
if query: | ||
self.history.append(Messages.User(query)) | ||
response = self._call(query) | ||
self.history.append(response.message_param) | ||
tools_and_outputs = [] | ||
if tools := response.tools: | ||
for tool in tools: | ||
print(f"[Calling Tool '{tool._name()}' with args {tool.args}]") | ||
tools_and_outputs.append((tool, tool.call())) | ||
self.history += response.tool_message_params(tools_and_outputs) | ||
return self._step("") | ||
else: | ||
return response.content | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
step_output = self._step(query) | ||
print(step_output) | ||
|
||
|
||
Librarian().run() |
52 changes: 52 additions & 0 deletions
52
examples/learn/agents/human_in_the_loop/google/string_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from mirascope.core import BaseDynamicConfig, Messages, google, prompt_template | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
def _ask_for_help(self, question: str) -> str: | ||
"""Asks for help from an expert.""" | ||
print("[Assistant Needs Help]") | ||
print(f"[QUESTION]: {question}") | ||
answer = input("[ANSWER]: ") | ||
print("[End Help]") | ||
return answer | ||
|
||
@google.call("gemini-1.5-flash") | ||
@prompt_template( | ||
""" | ||
SYSTEM: You are a librarian | ||
MESSAGES: {self.history} | ||
USER: {query} | ||
""" | ||
) | ||
def _call(self, query: str) -> BaseDynamicConfig: | ||
return {"tools": [self._ask_for_help]} | ||
|
||
def _step(self, query: str) -> str: | ||
if query: | ||
self.history.append(Messages.User(query)) | ||
response = self._call(query) | ||
self.history.append(response.message_param) | ||
tools_and_outputs = [] | ||
if tools := response.tools: | ||
for tool in tools: | ||
print(f"[Calling Tool '{tool._name()}' with args {tool.args}]") | ||
tools_and_outputs.append((tool, tool.call())) | ||
self.history += response.tool_message_params(tools_and_outputs) | ||
return self._step("") | ||
else: | ||
return response.content | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
step_output = self._step(query) | ||
print(step_output) | ||
|
||
|
||
Librarian().run() |
30 changes: 30 additions & 0 deletions
30
examples/learn/agents/state_management/google/base_message_param.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from mirascope.core import BaseMessageParam, google | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
@google.call("gemini-1.5-flash") | ||
def _call(self, query: str) -> list[google.GoogleMessageParam]: | ||
return [ | ||
BaseMessageParam(role="system", content="You are a librarian"), | ||
*self.history, | ||
BaseMessageParam(role="user", content=query), | ||
] | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
response = self._call(query) | ||
print(response.content) | ||
self.history += [ | ||
BaseMessageParam(role="user", content=query), | ||
response.message_param, | ||
] | ||
|
||
|
||
Librarian().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from mirascope.core import Messages, google | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
@google.call("gemini-1.5-flash") | ||
def _call(self, query: str) -> Messages.Type: | ||
return [ | ||
Messages.System("You are a librarian"), | ||
*self.history, | ||
Messages.User(query), | ||
] | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
response = self._call(query) | ||
print(response.content) | ||
self.history += [ | ||
Messages.User(query), | ||
response.message_param, | ||
] | ||
|
||
|
||
Librarian().run() |
30 changes: 30 additions & 0 deletions
30
examples/learn/agents/state_management/google/shorthand.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from mirascope.core import Messages, google | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
@google.call("gemini-1.5-flash") | ||
def _call(self, query: str) -> Messages.Type: | ||
return [ | ||
Messages.System("You are a librarian"), | ||
*self.history, | ||
Messages.User(query), | ||
] | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
response = self._call(query) | ||
print(response.content) | ||
self.history += [ | ||
Messages.User(query), | ||
response.message_param, | ||
] | ||
|
||
|
||
Librarian().run() |
32 changes: 32 additions & 0 deletions
32
examples/learn/agents/state_management/google/string_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from mirascope.core import Messages, google, prompt_template | ||
from pydantic import BaseModel | ||
|
||
|
||
class Librarian(BaseModel): | ||
history: list[google.GoogleMessageParam] = [] | ||
|
||
@google.call("gemini-1.5-flash") | ||
@prompt_template( | ||
""" | ||
SYSTEM: You are a librarian | ||
MESSAGES: {self.history} | ||
USER: {query} | ||
""" | ||
) | ||
def _call(self, query: str): ... | ||
|
||
def run(self) -> None: | ||
while True: | ||
query = input("(User): ") | ||
if query in ["exit", "quit"]: | ||
break | ||
print("(Assistant): ", end="", flush=True) | ||
response = self._call(query) | ||
print(response.content) | ||
self.history += [ | ||
Messages.User(query), | ||
response.message_param, | ||
] | ||
|
||
|
||
Librarian().run() |
Oops, something went wrong.