-
Notifications
You must be signed in to change notification settings - Fork 783
GenAI Utils | Initial Helpers for Inference #3732
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
Closed
keith-decker
wants to merge
88
commits into
open-telemetry:main
from
zhirafovod:util-genai-inference
Closed
Changes from 23 commits
Commits
Show all changes
88 commits
Select commit
Hold shift + click to select a range
00c2091
WIP initial code import
keith-decker 40e6c48
remove references to tool types
keith-decker 43526d6
add a simple unit test
keith-decker 76dbd57
rename exporter to emitter.
keith-decker 567e0a4
rename api file to client
keith-decker fd41dfb
Merge branch 'main' into util-genai-inference
keith-decker 4bd72aa
WIP gen_ai chat refactor
keith-decker 59414fa
Add provider.name, rename client to handler
keith-decker 5127c39
add message to log functions
keith-decker 66e0c26
remove events, emit structured logs
keith-decker 4346580
update documentation
keith-decker 4be03c4
first round of cleanup for lintcheck
keith-decker c19e4e6
typecheck fixes
keith-decker 11d937b
typecheck fixes
keith-decker fdc71a3
linting fixes
keith-decker 04d6e97
linting fixes, refactor for complexity
keith-decker a2e017a
typecheck fixes
keith-decker 92cd5c8
update documentation
keith-decker 770f878
rename context, update _to_semconv_dict name
keith-decker 78bc6bf
refactor: rename emitters to generators and update method names for c…
keith-decker b7360f8
refactor: convert API LogRecord to SDK LogRecord, add unit test
keith-decker 86152df
added changelog
keith-decker c0e03c4
Merge branch 'main' into util-genai-inference
keith-decker a5b04be
Merge branch 'main' into util-genai-inference
keith-decker 3c94ecd
Wip Convert input messages
keith-decker a59ca1e
wip, refactor chat generation to output message
keith-decker a8bb486
cleanup
keith-decker f64bf69
merge test files
keith-decker 4304819
lint updates
keith-decker f689ad1
remove logging, lower PR size
keith-decker b3bb75c
lint update
keith-decker fb30d45
check env for content capture
keith-decker fd45c43
check env for content capture on output
keith-decker aeaa319
lint updates
keith-decker 6a19e04
remove metrics to reduce PR size
keith-decker ad062e3
remove metrics file
keith-decker fc0cde0
cleanup docs, remove meter/logger provider
keith-decker 5cea4a6
remove overly complicated env check, add messages to test
keith-decker 8e5c6ab
update file doc strings
keith-decker 16f20b8
lint updates
keith-decker 5ba84ef
remove unused properties
keith-decker 381d38d
move utility function to utils
keith-decker b983dcd
Merge branch 'main' into util-genai-inference
keith-decker 3a37f43
Additional span attributes
keith-decker b769ed6
Merge branch 'util-genai-inference' of github.com:zhirafovod/opentele…
keith-decker 0776a7f
update span name
keith-decker 7071d0f
Revert "Additional span attributes"
keith-decker bb184da
remove unused thread lock
keith-decker 0b18708
update span name
keith-decker 4f8e860
Merge branch 'main' into util-genai-inference
keith-decker e72a320
Update documentation, rename system to provider
keith-decker a704fc6
cleanup docs and unclear code
keith-decker 54d753b
Merge branch 'main' into util-genai-inference
keith-decker 0d4f204
add unit test for parent/child relationship
keith-decker 82e4bff
cleanup some duplicated code
keith-decker d7c6187
cleanup duplicated start span code, move parent check into context ma…
keith-decker b12f865
remove unneccesary helper function
keith-decker b61437f
First commit for langchain instrumentation
wrisa 1a11630
removed env
wrisa 4f0e86c
added tool support and modified llm accordingly
wrisa 4e07998
Added evaluation span and event. Added log api for event
wrisa 0847f3b
added deepeval metric measure
wrisa b86d793
Fixing tests and adding tool call tests for langchain instrumentation
89388e1
Adding readme for test_langchain_llm.py
b26952d
WIP initial code import
keith-decker 8578d76
remove references to tool types
keith-decker 765758e
add a simple unit test
keith-decker 3dbe121
rename exporter to emitter.
keith-decker 2743109
rename api file to client
keith-decker 5c009b3
WIP gen_ai chat refactor
keith-decker 2b4d96c
Add provider.name, rename client to handler
keith-decker 5e723c4
add message to log functions
keith-decker 4404c20
remove events, emit structured logs
keith-decker a9f0f64
update documentation
keith-decker 9eb69bf
first round of cleanup for lintcheck
keith-decker c92fdec
typecheck fixes
keith-decker 91b18ad
typecheck fixes
keith-decker 09d6f4c
linting fixes
keith-decker 840e9fd
linting fixes, refactor for complexity
keith-decker 70e8d1d
typecheck fixes
keith-decker a1485d2
update documentation
keith-decker a734de7
rename context, update _to_semconv_dict name
keith-decker c5bc930
refactor: rename emitters to generators and update method names for c…
keith-decker ab9f170
refactor: convert API LogRecord to SDK LogRecord, add unit test
keith-decker 521824f
added changelog
keith-decker 7c017c4
Merge branch 'main' into util-genai-inference
keith-decker cab5ca0
clean up extra functions
keith-decker d97fdca
Merge branch 'genai-utils-e2e-dev' into util-genai-inference
zhirafovod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,13 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
69 changes: 69 additions & 0 deletions
69
util/opentelemetry-util-genai/src/opentelemetry/util/genai/data.py
This file contains hidden or 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,69 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from dataclasses import dataclass | ||
from typing import List, Literal, Optional, Type, TypedDict | ||
|
||
|
||
class TextPart(TypedDict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks very similar to #3718 @DylanRussell
keith-decker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: Literal["text"] | ||
content: str | ||
|
||
|
||
# Keep room for future parts without changing the return type | ||
# addition of tools can use Part = Union[TextPart, ToolPart] | ||
Part = TextPart | ||
|
||
|
||
class OtelMessage(TypedDict): | ||
role: str | ||
# role: Literal["user", "assistant", "system", "tool", "tool_message"] # TODO: check semconvs for allowed roles | ||
parts: List[Part] | ||
|
||
|
||
@dataclass | ||
class Message: | ||
content: str | ||
type: str | ||
name: str | ||
|
||
def _to_semconv_dict(self) -> OtelMessage: | ||
"""Convert the message to a dictionary suitable for OpenTelemetry semconvs. | ||
Ref: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/registry/attributes/gen-ai.md#gen-ai-input-messages | ||
""" | ||
|
||
# TODO: Support tool_call and tool_call response | ||
return { | ||
"role": self.type, | ||
"parts": [ | ||
{ | ||
"content": self.content, | ||
"type": "text", | ||
} | ||
], | ||
} | ||
|
||
|
||
@dataclass | ||
class ChatGeneration: | ||
content: str | ||
type: str | ||
finish_reason: Optional[str] = None | ||
|
||
|
||
@dataclass | ||
class Error: | ||
message: str | ||
type: Type[BaseException] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.