Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Google Gemini AI capabilities for AI monitoring #1232

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
95803cd
Adding Google Gemini AI capabilities for AI monitoring
harrykimpel Oct 7, 2024
fccfca6
Adding Google Gemini AI capabilities for AI monitoring
harrykimpel Oct 8, 2024
6a8fe99
Adding Google Gemini AI capabilities for AI monitoring
harrykimpel Oct 10, 2024
178eb89
Merge branch 'main' into main
mergify[bot] Oct 10, 2024
9eb77ec
Merge branch 'newrelic:main' into main
harrykimpel Oct 14, 2024
a4c4d01
Merge branch 'main' into main
mergify[bot] Oct 15, 2024
727df3a
Merge branch 'main' into main
mergify[bot] Oct 15, 2024
0866696
Merge branch 'main' into main
mergify[bot] Oct 28, 2024
e1de611
Minor updates to boto core instrumentation
harrykimpel Nov 5, 2024
22bbdf9
Merge branch 'main' of https://github.com/harrykimpel/newrelic-python…
harrykimpel Nov 5, 2024
0f05357
Adding Gemini test cases
harrykimpel Nov 8, 2024
4397547
Updating Gemini tests
harrykimpel Nov 12, 2024
2e734b1
Merge branch 'newrelic:main' into main
harrykimpel Nov 12, 2024
7b1c601
Clean up tox changes
TimPansino Nov 13, 2024
d4ab634
Merge branch 'main' into main
mergify[bot] Nov 14, 2024
db7378c
Merge branch 'main' into main
mergify[bot] Nov 18, 2024
c7c5737
Updating Gemini unit tests
harrykimpel Nov 20, 2024
918ccfe
Merge branch 'main' of https://github.com/harrykimpel/newrelic-python…
harrykimpel Nov 20, 2024
c4d6a46
Updating Gemini unit tests
harrykimpel Nov 20, 2024
52bf989
Merge branch 'newrelic:main' into main
harrykimpel Nov 22, 2024
00e0ac7
Merge branch 'main' into main
mergify[bot] Nov 22, 2024
2584748
Merge branch 'main' into main
mergify[bot] Nov 22, 2024
1a688df
Merge branch 'main' into main
harrykimpel Nov 26, 2024
c12aee7
Merge branch 'main' into main
mergify[bot] Dec 4, 2024
9dcec50
Merge branch 'main' into main
mergify[bot] Dec 5, 2024
195d0c8
Merge branch 'main' into main
mergify[bot] Dec 9, 2024
a392872
Merge branch 'main' into main
mergify[bot] Dec 9, 2024
3b09621
Merge branch 'main' into main
mergify[bot] Dec 12, 2024
ccd6b5c
Merge branch 'main' into main
mergify[bot] Dec 12, 2024
5ad5afb
Merge branch 'main' into main
mergify[bot] Dec 13, 2024
5b65c5e
Merge branch 'main' into main
mergify[bot] Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions newrelic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,11 @@ def _process_trace_cache_import_hooks():


def _process_module_builtin_defaults():
_process_module_definition(
"google.generativeai",
"newrelic.hooks.mlmodel_gemini",
"instrument_gemini_api_resources_chat_completion",
)
_process_module_definition(
"openai.api_resources.embedding",
"newrelic.hooks.mlmodel_openai",
Expand Down
10 changes: 6 additions & 4 deletions newrelic/hooks/external_botocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def create_chat_completion_message_event(

def extract_bedrock_titan_text_model_request(request_body, bedrock_attrs):
request_body = json.loads(request_body)

request_config = request_body.get("textGenerationConfig", {})

input_message_list = [{"role": "user", "content": request_body.get("inputText")}]
Expand All @@ -225,7 +226,7 @@ def extract_bedrock_mistral_text_model_request(request_body, bedrock_attrs):
def extract_bedrock_titan_text_model_response(response_body, bedrock_attrs):
if response_body:
response_body = json.loads(response_body)

output_message_list = [
{"role": "assistant", "content": result["outputText"]} for result in response_body.get("results", [])
]
Expand Down Expand Up @@ -315,10 +316,10 @@ def extract_bedrock_ai21_j2_model_response(response_body, bedrock_attrs):

def extract_bedrock_claude_model_request(request_body, bedrock_attrs):
request_body = json.loads(request_body)

if "messages" in request_body:
input_message_list = [
{"role": message.get("role", "user"), "content": message.get("content")}
{"role": message.get("role", "user"), "content": message.get("content")[0].get("text")}
for message in request_body.get("messages")
]
else:
Expand All @@ -333,8 +334,9 @@ def extract_bedrock_claude_model_request(request_body, bedrock_attrs):
def extract_bedrock_claude_model_response(response_body, bedrock_attrs):
if response_body:
response_body = json.loads(response_body)

role = response_body.get("role", "assistant")
content = response_body.get("content") or response_body.get("completion")
content = response_body.get("content")[0].get("text") or response_body.get("completion")
output_message_list = [{"role": role, "content": content}]
bedrock_attrs["response.choices.finish_reason"] = response_body.get("stop_reason")
bedrock_attrs["output_message_list"] = output_message_list
Expand Down
Loading