-
Notifications
You must be signed in to change notification settings - Fork 93
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
hellovai/tracing #1350
Draft
hellovai
wants to merge
9
commits into
canary
Choose a base branch
from
hellovai/tracing
base: canary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
hellovai/tracing #1350
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ca41486
tracing impl for context
sxlijin 5dd25f7
add new tracing client impl
sxlijin a6bcd67
stash everything
sxlijin 5e439b4
compile again
sxlijin 61c3639
move tracing types around
sxlijin 7da6b9d
one more
sxlijin 3222f3f
Merge branch 'canary' into sam/tracing2
hellovai 39c686f
Merge latest
hellovai 7ba561b
tracing WIP
hellovai 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 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
node = "20.14" | ||
ruby = "3.1" | ||
pnpm = "9.9" | ||
poetry = "1.8.4" | ||
poetry = "1.8.5" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ mod constraint; | |
mod map; | ||
mod media; | ||
mod minijinja; | ||
pub mod tracing; | ||
|
||
mod baml_value; | ||
mod field_type; | ||
|
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,131 @@ | ||
use anyhow::Result; | ||
use crate::BamlValue; | ||
|
||
// TODO: use a prefixed UUID type for this | ||
type SpanId = String; | ||
|
||
#[derive(Clone, PartialEq, Eq, Hash)] | ||
pub struct FunctionId(pub SpanId); | ||
|
||
#[derive(Clone, PartialEq, Eq, Hash)] | ||
pub struct ContentId(pub SpanId); | ||
|
||
// THESE ARE NOT CLONEABLE!! | ||
pub struct LogEvent { | ||
/* | ||
* (span_id, content_span_id) is a unique identifier for a log event | ||
* The query (span_id, *) gets all logs for a function call | ||
*/ | ||
|
||
pub span_id: FunctionId, | ||
pub content_span_id: ContentId, | ||
|
||
// The chain of spans that lead to this log event | ||
// Includes span_id at the last position (content_span_id is not included) | ||
pub span_chain: Vec<FunctionId>, | ||
|
||
// The timestamp of the log | ||
pub timestamp: web_time::Instant, | ||
// The content of the log | ||
pub content: LogEventContent, | ||
} | ||
|
||
|
||
pub enum LogEventContent { | ||
// All start events | ||
FunctionStart(FunctionStart), | ||
// All end events | ||
FunctionEnd(FunctionEnd), | ||
|
||
// The rest are intermediate events that happen between start and end | ||
|
||
// LLM request | ||
LLMRequest(LLMRequest), | ||
// Raw HTTP request to the LLM | ||
RawLLMRequest(HTTPRequest), | ||
|
||
// Do to streaming, its possible to have multiple responses for a single request | ||
// ---- | ||
// Raw HTTP response from the LLM | ||
RawLLMResponse(HTTPResponse), | ||
// Parsed LLM response | ||
LLMResponse(Result<LLMResponse>), | ||
// ---- | ||
|
||
// We don't want to store the parsed LLM response in the log event | ||
// as we have it in FunctionEnd | ||
Parsed(Result<()>), | ||
} | ||
|
||
pub struct BamlOptions { | ||
pub type_builder: Option<serde_json::Value>, | ||
pub client_registry: Option<serde_json::Value>, | ||
} | ||
|
||
pub struct FunctionStart { | ||
pub name: String, | ||
pub args: Vec<BamlValue>, | ||
pub options: BamlOptions, | ||
} | ||
|
||
pub struct FunctionEnd { | ||
pub result: Result<BamlValue>, | ||
// Everything below is duplicated from the start event | ||
// to deal with the case where the log is dropped. | ||
// P2: as we can for now assume logs are not dropped, | ||
|
||
// pub name: String, | ||
// pub start_timestamp: web_time::Instant, | ||
// pub start_args: Vec<BamlValue>, | ||
} | ||
|
||
// LLM specific events | ||
|
||
// TODO: fix this. | ||
pub type Prompt = serde_json::Value; | ||
|
||
pub enum LLMClient { | ||
Ref(String), | ||
ShortHand(String, String), | ||
} | ||
|
||
pub struct LLMRequest { | ||
pub client: LLMClient, | ||
pub params: serde_json::Value, | ||
pub prompt: Prompt, | ||
} | ||
|
||
pub struct HTTPRequest { | ||
// since LLM requests could be made in parallel, we need to match the response to the request | ||
pub request_id: ContentId, | ||
pub url: String, | ||
pub method: String, | ||
pub headers: serde_json::Value, | ||
pub body: serde_json::Value, | ||
} | ||
|
||
pub struct HTTPResponse { | ||
// since LLM requests could be made in parallel, we need to match the response to the request | ||
pub request_id: ContentId, | ||
pub status: u16, | ||
pub headers: serde_json::Value, | ||
pub body: serde_json::Value, | ||
} | ||
|
||
|
||
pub struct LLMResponse { | ||
// since LLM requests could be made in parallel, we need to match the response to the request | ||
pub request_id: ContentId, | ||
// Fully qualified model name | ||
pub finish_reason: String, | ||
pub model: String, | ||
pub usage: LLMUsage, | ||
pub string_output: String, | ||
} | ||
|
||
pub struct LLMUsage { | ||
pub input_tokens: Option<u64>, | ||
pub output_tokens: Option<u64>, | ||
pub total_tokens: Option<u64>, | ||
} | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
LogEvent
struct is missingClone
,PartialEq
, andHash
traits which are needed for proper event tracking and comparison. Add these trait derivations.📝 Committable Code Suggestion