Skip to content

Commit

Permalink
An initial version of ResultManager. Write the SQL for use with gener…
Browse files Browse the repository at this point in the history
…atec.
  • Loading branch information
jlewi committed Sep 21, 2024
1 parent 3f817ef commit 0835124
Show file tree
Hide file tree
Showing 17 changed files with 729 additions and 810 deletions.
3 changes: 3 additions & 0 deletions app/api/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type Experiment struct {
}

type ExperimentSpec struct {
// AgentAddress is the address of the agent to use to generate completions
AgentAddress string `json:"agentAddress" yaml:"agentAddress"`

// EvalDir is the directory containing the evaluation the evaluation input
EvalDir string `json:"evalDir" yaml:"evalDir"`

Expand Down
9 changes: 9 additions & 0 deletions app/pkg/analyze/fsql/eval_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- name: UpdateResult :exec
INSERT OR REPLACE INTO results
(id, time, proto_json)
VALUES
(?, ?, ?);

-- name: GetResult :one
SELECT * FROM results
WHERE id = ?;
41 changes: 41 additions & 0 deletions app/pkg/analyze/fsql/eval_query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/pkg/analyze/fsql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/pkg/analyze/fsql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ WHERE contextID = ?;
INSERT OR REPLACE INTO sessions
(contextID, startTime, endTime, selectedId, selectedKind, total_input_tokens, total_output_tokens, num_generate_traces, proto)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?);
(?, ?, ?, ?, ?, ?, ?, ?, ?);
11 changes: 11 additions & 0 deletions app/pkg/analyze/fsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ CREATE TABLE IF NOT EXISTS sessions (
-- TODO(jeremy): Should we store the proto in JSON format so that we can run SQL queries on values in it?
proto BLOB
);

-- Results contains evaluation results
CREATE TABLE IF NOT EXISTS results (
id VARCHAR(255) PRIMARY KEY,
-- time is the time of the evaluation example
-- protobufs can't have null timestamps so no point allowing nulls
time TIMESTAMP NOT NULL,

-- The JSON serialization of the proto.
proto_json TEXT NOT NULL
);
4 changes: 3 additions & 1 deletion app/pkg/analyze/fsql/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: "2"
sql:
- engine: "sqlite"
queries: "query.sql"
queries:
- "eval_query.sql"
- "query.sql"
schema: "schema.sql"
gen:
go:
Expand Down
5 changes: 4 additions & 1 deletion app/pkg/analyze/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ func (m *SessionsManager) DumpExamples(ctx context.Context, request *connect.Req
}

// protoToRow converts from the proto representation of a session to the database row representation.
//
// TODO(jeremy): I think it would be better to make the return type fsql.UpdateSessionParams. Right now the only
// place this function gets called is in the Update method and the returned value is immediately converted to
// fsql.UpdateSessionParams.
func protoToRow(session *logspb.Session) (*fsql.Session, error) {
log := logs.NewLogger()
protoBytes, err := proto.Marshal(session)
Expand All @@ -303,7 +307,6 @@ func protoToRow(session *logspb.Session) (*fsql.Session, error) {
}
}

// TODO: How do we deal with the end/starttime? In sqlc should we specify the type as timestamp?
return &fsql.Session{
Contextid: session.ContextId,
Starttime: session.StartTime.AsTime(),
Expand Down
Loading

0 comments on commit 0835124

Please sign in to comment.