|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "log" |
| 7 | + "os" |
7 | 8 | "testing" |
| 9 | + "time" |
8 | 10 |
|
9 | 11 | "github.com/google/uuid" |
10 | 12 | "github.com/tmc/langchaingo/llms" |
@@ -122,6 +124,7 @@ func TestRun(t *testing.T) { |
122 | 124 |
|
123 | 125 | // use 2 chains |
124 | 126 | t.Run("use with 2 traces", func(t *testing.T) { |
| 127 | + t.Skip() |
125 | 128 | // Create a new client |
126 | 129 | runId := uuid.New().String() |
127 | 130 | client := NewClient("") |
@@ -201,4 +204,92 @@ func TestRun(t *testing.T) { |
201 | 204 |
|
202 | 205 | }) |
203 | 206 |
|
| 207 | + t.Run("use with 2 traces and SimpleRun", func(t *testing.T) { |
| 208 | + // Create a new client |
| 209 | + runId := uuid.New().String() |
| 210 | + client := NewClient(os.Getenv("LANGSMITH_API_KEY")) |
| 211 | + |
| 212 | + opts := []openai.Option{ |
| 213 | + openai.WithModel("gpt-3.5-turbo-0125"), |
| 214 | + openai.WithEmbeddingModel("text-embedding-3-large"), |
| 215 | + } |
| 216 | + llm, err := openai.New(opts...) |
| 217 | + if err != nil { |
| 218 | + log.Fatal(err) |
| 219 | + } |
| 220 | + |
| 221 | + ctx := context.Background() |
| 222 | + |
| 223 | + content := []llms.MessageContent{ |
| 224 | + llms.TextParts(llms.ChatMessageTypeSystem, "You are a company branding design wizard."), |
| 225 | + llms.TextParts(llms.ChatMessageTypeHuman, "What would be a good company name a company that makes colorful socks?"), |
| 226 | + } |
| 227 | + |
| 228 | + if err != nil { |
| 229 | + t.Errorf("Error running: %v", err) |
| 230 | + } |
| 231 | + startTime := time.Now().UTC() |
| 232 | + out, err := llm.GenerateContent(ctx, content) |
| 233 | + if err != nil { |
| 234 | + t.Errorf("Error running: %v", err) |
| 235 | + |
| 236 | + } |
| 237 | + runPayload := &RunPayload{ |
| 238 | + Name: "langsmithgo-llm", |
| 239 | + SessionName: "langsmithgo", |
| 240 | + RunType: LLM, |
| 241 | + RunID: runId, |
| 242 | + Tags: []string{"llm"}, |
| 243 | + StartTime: startTime, |
| 244 | + Inputs: map[string]interface{}{ |
| 245 | + "prompt": content, // Ensure 'output' is properly defined and is of type that has a String method |
| 246 | + "model": "gpt-3.5-turbo", |
| 247 | + "temperature": 0.7, // Assuming 'temperature' should be a float, not a string |
| 248 | + }, |
| 249 | + Outputs: map[string]interface{}{ |
| 250 | + "output": out, |
| 251 | + }, |
| 252 | + EndTime: time.Now().UTC(), |
| 253 | + } |
| 254 | + |
| 255 | + err = client.RunSingle(runPayload) |
| 256 | + |
| 257 | + if err != nil { |
| 258 | + t.Errorf("Error running: %v", err) |
| 259 | + } |
| 260 | + |
| 261 | + embdId := uuid.New().String() |
| 262 | + // create embedding |
| 263 | + |
| 264 | + startTime = time.Now().UTC() |
| 265 | + |
| 266 | + embedings, err := llm.CreateEmbedding(ctx, []string{"ola", "mundo"}) |
| 267 | + if err != nil { |
| 268 | + log.Fatal(err) |
| 269 | + } |
| 270 | + |
| 271 | + err = client.RunSingle(&RunPayload{ |
| 272 | + Name: "langsmithgo-llm", |
| 273 | + SessionName: "langsmithgo", |
| 274 | + RunType: Embedding, |
| 275 | + StartTime: startTime, |
| 276 | + RunID: embdId, |
| 277 | + ParentID: runId, |
| 278 | + Tags: []string{"llm"}, |
| 279 | + Inputs: map[string]interface{}{ |
| 280 | + "prompt": out.Choices[0].Content, // Ensure 'output' is properly defined and is of type that has a String method |
| 281 | + "model": "gpt-3.5-turbo", |
| 282 | + "temperature": 0.7, // Assuming 'temperature' should be a float, not a string |
| 283 | + }, |
| 284 | + Outputs: map[string]interface{}{ |
| 285 | + "output": embedings, |
| 286 | + }, |
| 287 | + EndTime: time.Now().UTC(), |
| 288 | + }) |
| 289 | + |
| 290 | + if err != nil { |
| 291 | + log.Fatal(err) |
| 292 | + } |
| 293 | + |
| 294 | + }) |
204 | 295 | } |
0 commit comments