Skip to content

Commit

Permalink
Merge pull request #27 from yubing744/owen/show_llm_model
Browse files Browse the repository at this point in the history
feat: show model ok
  • Loading branch information
yubing744 authored May 27, 2024
2 parents 9403d2b + b61a430 commit 7d2b06e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: true

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22.0'

- name: Cache Go modules
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
run: go mod download

- name: Build
run: make build

- name: Run unit tests
run: make unit-test
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: clean build test run docker-* tag release
.PHONY: clean build unit-test run docker-* tag release

NAME=trading-gpt
VERSION=0.22.3
VERSION=0.23.0

clean:
rm -rf build/*
Expand All @@ -12,7 +12,7 @@ build: clean
build-linux:
CGO_ENABLED=0 GOOS=linux go build -o ./build/bbgo ./main.go

test:
unit-test:
go test ./pkg/...

run: build
Expand Down
1 change: 1 addition & 0 deletions pkg/agents/agent_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type GenResult struct {
Texts []string
Model string
}

type IAgent interface {
Expand Down
9 changes: 9 additions & 0 deletions pkg/agents/trading/trading_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ func (a *TradingAgent) GenActions(ctx context.Context, session types.ISession, m
log.WithField("text", text).Info("resp.Choices[0].Text")

result.Texts = append(result.Texts, text)

// extract model
extInfo := resp.Choices[0].GenerationInfo
if extInfo != nil {
model, ok := extInfo["model"]
if ok {
result.Model = model.(string)
}
}
}

if len(result.Texts) > 0 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/jarvis.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ func (s *Strategy) agentAction(ctx context.Context, chatSession ttypes.ISession,
}
}

if resp.Model != "" {
s.replyMsg(ctx, chatSession, fmt.Sprintf("Generated by LLM model: %s", resp.Model))
}

if len(actions) > 0 {
if chatSession.HasRole(ttypes.RoleAdmin) {
if len(actions) > 1 {
Expand Down
13 changes: 12 additions & 1 deletion pkg/llms/llm_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,23 @@ func (mgr *LLMManager) GenerateContent(ctx context.Context, messages []llms.Mess
return nil, errors.Wrap(err2, "get secondly fail")
}

return llm2.GenerateContent(ctx, messages, options...)
resp2, err := llm2.GenerateContent(ctx, messages, options...)
setModel(resp, mgr.secondly)
return resp2, err
}

setModel(resp, mgr.primary)
return resp, nil
}

func setModel(resp *llms.ContentResponse, model string) {
if resp != nil {
for _, choice := range resp.Choices {
choice.GenerationInfo["model"] = model
}
}
}

// Call is a simplified interface for a text-only Model, generating a single
// string response from a single string prompt.
//
Expand Down

0 comments on commit 7d2b06e

Please sign in to comment.