Skip to content

Commit

Permalink
allow setting of telemetry options
Browse files Browse the repository at this point in the history
  • Loading branch information
rgarcia committed Feb 23, 2025
1 parent b5367c4 commit dd307cc
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 14 deletions.
42 changes: 41 additions & 1 deletion packages/core/src/agent/agent.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createOpenAI } from '@ai-sdk/openai';
import { InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { config } from 'dotenv';
import { describe, it, expect, vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { z } from 'zod';

import { TestIntegration } from '../integration/openapi-toolset.mock';
Expand Down Expand Up @@ -275,4 +277,42 @@ describe('agent', () => {
expect(sanitizedMessages).not.toContainEqual(toolCallThree);
expect(sanitizedMessages).toHaveLength(2);
});

it('should use telemetry options when generating a response', async () => {
const electionAgent = new Agent({
name: 'US Election agent',
instructions: 'You know about the past US elections',
model: openai('gpt-4o'),
});

const memoryExporter = new InMemorySpanExporter();
const tracerProvider = new NodeTracerProvider({
spanProcessors: [new SimpleSpanProcessor(memoryExporter)],
});
tracerProvider.register();

const mastra = new Mastra({
agents: { electionAgent },
telemetry: {
enabled: true,
serviceName: 'test-service',
export: {
type: 'custom',
exporter: memoryExporter,
},
},
});
const agentOne = mastra.getAgent('electionAgent');

const response = await agentOne.generate('Who won the 2016 US presidential election?', {

Check warning on line 307 in packages/core/src/agent/agent.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'response' is assigned a value but never used. Allowed unused vars must match /^ignored/u
telemetryOptions: { functionId: 'test-function-id', metadata: { test: 'test' } },
});

const spans = memoryExporter.getFinishedSpans();
const aiSpan = spans.find(span => span.name === 'ai.generateText');
expect(aiSpan).toBeDefined();
expect(aiSpan?.attributes['ai.telemetry.metadata.test']).toBe('test');
expect(aiSpan?.attributes['resource.name']).toBe('test-function-id');
await tracerProvider.shutdown();
});
});
12 changes: 9 additions & 3 deletions packages/core/src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import type {
CoreMessage,
CoreToolMessage,
CoreUserMessage,
LanguageModelV1,
TextPart,
ToolCallPart,
UserContent,
LanguageModelV1,
} from 'ai';
import { randomUUID } from 'crypto';

Check warning on line 12 in packages/core/src/agent/index.ts

View workflow job for this annotation

GitHub Actions / Lint

`crypto` import should occur before type import of `ai`
import type { JSONSchema7 } from 'json-schema';
import { z } from 'zod';
import type { ZodSchema } from 'zod';
import { z } from 'zod';

import type { MastraPrimitives } from '../action';
import { MastraBase } from '../base';
import type { Metric } from '../eval';
import { AvailableHooks, executeHook } from '../hooks';
import type { GenerateReturn, StreamReturn } from '../llm';
import { MastraLLM } from '../llm/model';
import type { MastraLLMBase } from '../llm/model';
import { MastraLLM } from '../llm/model';
import { LogLevel, RegisteredLogger } from '../logger';
import type { MastraMemory } from '../memory/memory';
import type { MemoryConfig, StorageThreadType } from '../memory/types';
Expand Down Expand Up @@ -777,6 +777,7 @@ export class Agent<
output = 'text',
temperature,
toolChoice = 'auto',
telemetryOptions,
}: AgentGenerateOptions<Z> = {},
): Promise<GenerateReturn<Z>> {
let messagesToUse: CoreMessage[] = [];
Expand Down Expand Up @@ -824,6 +825,7 @@ export class Agent<
runId: runIdToUse,
temperature,
toolChoice,
telemetryOptions,
});

const outputText = result.text;
Expand All @@ -843,6 +845,7 @@ export class Agent<
runId: runIdToUse,
temperature,
toolChoice,
telemetryOptions,
});

const outputText = JSON.stringify(result.object);
Expand All @@ -867,6 +870,7 @@ export class Agent<
output = 'text',
temperature,
toolChoice = 'auto',
telemetryOptions,
}: AgentStreamOptions<Z> = {},
): Promise<StreamReturn<Z>> {
const runIdToUse = runId || randomUUID();
Expand Down Expand Up @@ -930,6 +934,7 @@ export class Agent<
maxSteps,
runId: runIdToUse,
toolChoice,
telemetryOptions,
}) as unknown as StreamReturn<Z>;
}

Expand Down Expand Up @@ -959,6 +964,7 @@ export class Agent<
maxSteps,
runId: runIdToUse,
toolChoice,
telemetryOptions,
}) as unknown as StreamReturn<Z>;
}
}
4 changes: 3 additions & 1 deletion packages/core/src/agent/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LanguageModelV1 } from 'ai';
import type { LanguageModelV1, TelemetrySettings } from 'ai';
import type { JSONSchema7 } from 'json-schema';
import type { ZodSchema } from 'zod';

Expand Down Expand Up @@ -42,6 +42,7 @@ export interface AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefi
output?: OutputType | Z;
temperature?: number;
toolChoice?: 'auto' | 'required';
telemetryOptions?: TelemetrySettings;
}

export interface AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
Expand All @@ -57,4 +58,5 @@ export interface AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefine
output?: OutputType | Z;
temperature?: number;
toolChoice?: 'auto' | 'required';
telemetryOptions?: TelemetrySettings;
}
2 changes: 1 addition & 1 deletion packages/core/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BaseLogMessage, Logger, LogLevel } from './logger';
import { createLogger, RegisteredLogger } from './logger';
import type { Logger, LogLevel, BaseLogMessage } from './logger';
import type { Telemetry } from './telemetry';

export class MastraBase {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/llm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
LanguageModelV1,
StreamObjectResult,
StreamTextResult,
TelemetrySettings,
} from 'ai';
import type { JSONSchema7 } from 'json-schema';
import type { z, ZodSchema } from 'zod';
Expand Down Expand Up @@ -82,6 +83,7 @@ export type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = und
convertedTools?: Record<string, CoreTool>;
output?: OutputType | Z;
temperature?: number;
telemetryOptions?: TelemetrySettings;
};

export type LLMTextOptions = {
Expand All @@ -92,6 +94,7 @@ export type LLMTextOptions = {
toolChoice?: 'auto' | 'required';
maxSteps?: number;
temperature?: number;
telemetryOptions?: TelemetrySettings;
} & Run;

export type LLMTextObjectOptions<T> = LLMTextOptions & {
Expand All @@ -107,6 +110,7 @@ export type LLMInnerStreamOptions = {
maxSteps?: number;
temperature?: number;
toolChoice?: 'auto' | 'required';
telemetryOptions?: TelemetrySettings;
} & Run;

export type LLMStreamObjectOptions<T> = LLMInnerStreamOptions & {
Expand Down
37 changes: 29 additions & 8 deletions packages/core/src/llm/model/model.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { generateText, generateObject, jsonSchema, streamText, streamObject } from 'ai';
import type { LanguageModel, Schema, CoreMessage } from 'ai';
import type { CoreMessage, LanguageModel, Schema } from 'ai';
import { generateObject, generateText, jsonSchema, streamObject, streamText } from 'ai';
import type { JSONSchema7 } from 'json-schema';
import { z } from 'zod';
import type { ZodSchema } from 'zod';
import { z } from 'zod';

import type {
GenerateReturn,
LLMTextOptions,
LLMInnerStreamOptions,
LLMStreamObjectOptions,
LLMStreamOptions,
LLMTextObjectOptions,
LLMTextOptions,
StreamReturn,
} from '../';
import type { MastraPrimitives } from '../../action';
Expand Down Expand Up @@ -114,6 +114,7 @@ export class MastraLLM extends MastraLLMBase {
temperature,
toolChoice = 'auto',
onStepFinish,
telemetryOptions,
}: LLMTextOptions) {
const model = this.#model;

Expand Down Expand Up @@ -159,7 +160,10 @@ export class MastraLLM extends MastraLLMBase {
return await generateText({

Check failure on line 160 in packages/core/src/llm/model/model.ts

View workflow job for this annotation

GitHub Actions / test

src/agent/agent.test.ts > agent > should get a text response from the agent

AI_APICallError: You didn't provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys. ❯ ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:59:16 ❯ postToApi ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:81:28 ❯ OpenAIChatLanguageModel.doGenerate ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/openai/src/openai-chat-language-model.ts:367:50 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:348:30 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ _retryWithExponentialBackoff ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/util/retry-with-exponential-backoff.ts:36:12 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:308:32 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ MastraLLM.__text src/llm/model/model.ts:160:12 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { url: 'https://api.openai.com/v1/chat/completions', requestBodyValues: { model: 'gpt-4o', logit_bias: undefined, logprobs: undefined, top_logprobs: undefined, user: undefined, parallel_tool_calls: undefined, max_tokens: undefined, temperature: +0, top_p: undefined, frequency_penalty: undefined, presence_penalty: undefined, response_format: undefined, stop: undefined, seed: undefined, max_completion_tokens: undefined, store: undefined, metadata: undefined, prediction: undefined, reasoning_effort: undefined, messages: [ { role: 'system', content: 'You know about the past US elections. Today\'s date is 2025-02-23T22:21:21.946Z' }, { role: 'user', content: 'Who won the 2016 US presidential election?' } ], tools: undefined, tool_choice: undefined, functions: undefined, function_call: undefined }, statusCode: 401, responseHeaders: { 'alt-svc': 'h3=":443"; ma=86400', 'cf-cache-status': 'DYNAMIC', 'cf-ray': '916a9bc48eac6893-SJC', connection: 'keep-alive', 'content-length': '496', 'content-type': 'application/json; charset=utf-8', date: 'Sun, 23 Feb 2025 22:21:22 GMT', server: 'cloudflare', 'set-cookie': '_cfuvid=7usKNuCRCJ1EfwTsPikZHN6SLZuWsKBDYNXXsqmIcX8-1740349282034-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', vary: 'Origin', 'x-content-type-options': 'nosniff', 'x-request-id': 'req_0ce272248bfdf24dde24eceddf3341da' }, responseBody: '{\n "error": {\n "message": "You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",\n "type": "invalid_request_error",\n "param": null,\n "code": null\n }\n}\n', isRetryable: false, data: { error: { message: 'You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.', type: 'invalid_request_error', param: null, code: null } } }

Check failure on line 160 in packages/core/src/llm/model/model.ts

View workflow job for this annotation

GitHub Actions / test

src/agent/agent.test.ts > agent > should call findUserTool

AI_APICallError: You didn't provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys. ❯ ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:59:16 ❯ postToApi ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:81:28 ❯ OpenAIChatLanguageModel.doGenerate ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/openai/src/openai-chat-language-model.ts:367:50 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:348:30 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ _retryWithExponentialBackoff ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/util/retry-with-exponential-backoff.ts:36:12 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:308:32 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ MastraLLM.__text src/llm/model/model.ts:160:12 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { url: 'https://api.openai.com/v1/chat/completions', requestBodyValues: { model: 'gpt-4o', logit_bias: undefined, logprobs: undefined, top_logprobs: undefined, user: undefined, parallel_tool_calls: undefined, max_tokens: undefined, temperature: +0, top_p: undefined, frequency_penalty: undefined, presence_penalty: undefined, response_format: undefined, stop: undefined, seed: undefined, max_completion_tokens: undefined, store: undefined, metadata: undefined, prediction: undefined, reasoning_effort: undefined, messages: [ { role: 'system', content: 'You are an agent that can get list of users using findUserTool.. Today\'s date is 2025-02-23T22:21:22.259Z' }, { role: 'user', content: 'Find the user with name - Dero Israel' } ], tools: [ { type: 'function', function: { name: 'findUserTool', description: 'This is a test tool that returns the name and email', parameters: { type: 'object', properties: { name: { type: 'string' } }, required: [ 'name' ], additionalProperties: false, '$schema': 'http://json-schema.org/draft-07/schema#' }, strict: undefined } } ], tool_choice: 'required', functions: undefined, function_call: undefined }, statusCode: 401, responseHeaders: { 'alt-svc': 'h3=":443"; ma=86400', 'cf-cache-status': 'DYNAMIC', 'cf-ray': '916a9bc62b3667a5-SJC', connection: 'keep-alive', 'content-length': '496', 'content-type': 'application/json; charset=utf-8', date: 'Sun, 23 Feb 2025 22:21:22 GMT', server: 'cloudflare', 'set-cookie': '_cfuvid=rUqdLozbPKlDvPkW5v8WfRSWUzXeOV1Dh59sN1ZCspU-1740349282288-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', vary: 'Origin', 'x-content-type-options': 'nosniff', 'x-request-id': 'req_ca241ad554c1b7d84aa250243af9a63c' }, responseBody: '{\n "error": {\n "message": "You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",\n "type": "invalid_request_error",\n "param": null,\n "code": null\n }\n}\n', isRetryable: false, data: { error: { message: 'You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and ar

Check failure on line 160 in packages/core/src/llm/model/model.ts

View workflow job for this annotation

GitHub Actions / test

src/agent/agent.test.ts > agent > should call testTool from TestIntegration

AI_APICallError: You didn't provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys. ❯ ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:59:16 ❯ postToApi ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:81:28 ❯ OpenAIChatLanguageModel.doGenerate ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/openai/src/openai-chat-language-model.ts:367:50 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:348:30 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ _retryWithExponentialBackoff ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/util/retry-with-exponential-backoff.ts:36:12 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:308:32 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ MastraLLM.__text src/llm/model/model.ts:160:12 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { url: 'https://api.openai.com/v1/chat/completions', requestBodyValues: { model: 'gpt-4o', logit_bias: undefined, logprobs: undefined, top_logprobs: undefined, user: undefined, parallel_tool_calls: undefined, max_tokens: undefined, temperature: +0, top_p: undefined, frequency_penalty: undefined, presence_penalty: undefined, response_format: undefined, stop: undefined, seed: undefined, max_completion_tokens: undefined, store: undefined, metadata: undefined, prediction: undefined, reasoning_effort: undefined, messages: [ { role: 'system', content: 'You are an agent that call testTool. Today\'s date is 2025-02-23T22:21:22.291Z' }, { role: 'user', content: 'Call testTool' } ], tools: [ { type: 'function', function: { name: 'testTool', description: 'This is a test integration tol', parameters: { type: 'object', properties: {}, additionalProperties: false, '$schema': 'http://json-schema.org/draft-07/schema#' }, strict: undefined } } ], tool_choice: 'required', functions: undefined, function_call: undefined }, statusCode: 401, responseHeaders: { 'alt-svc': 'h3=":443"; ma=86400', 'cf-cache-status': 'DYNAMIC', 'cf-ray': '916a9bc65fb16893-SJC', connection: 'keep-alive', 'content-length': '496', 'content-type': 'application/json; charset=utf-8', date: 'Sun, 23 Feb 2025 22:21:22 GMT', server: 'cloudflare', 'set-cookie': '_cfuvid=m5pW_9SbdSCz2x0SUS5CJcuR2jm_LlGnRtTZG.Dq6g0-1740349282331-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', vary: 'Origin', 'x-content-type-options': 'nosniff', 'x-request-id': 'req_34155d2d93baaba090cce9e87c87f9a1' }, responseBody: '{\n "error": {\n "message": "You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",\n "type": "invalid_request_error",\n "param": null,\n "code": null\n }\n}\n', isRetryable: false, data: { error: { message: 'You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.', type:

Check failure on line 160 in packages/core/src/llm/model/model.ts

View workflow job for this annotation

GitHub Actions / test

src/agent/agent.test.ts > agent > should use telemetry options when generating a response

AI_APICallError: You didn't provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys. ❯ ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:59:16 ❯ postToApi ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:81:28 ❯ OpenAIChatLanguageModel.doGenerate ../../node_modules/.pnpm/@AI-SDK[email protected][email protected]/node_modules/@ai-sdk/openai/src/openai-chat-language-model.ts:367:50 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:348:30 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ _retryWithExponentialBackoff ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/util/retry-with-exponential-backoff.ts:36:12 ❯ fn ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/generate-text/generate-text.ts:308:32 ❯ ../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/ai/core/telemetry/record-span.ts:18:22 ❯ MastraLLM.__text src/llm/model/model.ts:160:12 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { url: 'https://api.openai.com/v1/chat/completions', requestBodyValues: { model: 'gpt-4o', logit_bias: undefined, logprobs: undefined, top_logprobs: undefined, user: undefined, parallel_tool_calls: undefined, max_tokens: undefined, temperature: +0, top_p: undefined, frequency_penalty: undefined, presence_penalty: undefined, response_format: undefined, stop: undefined, seed: undefined, max_completion_tokens: undefined, store: undefined, metadata: undefined, prediction: undefined, reasoning_effort: undefined, messages: [ { role: 'system', content: 'You know about the past US elections. Today\'s date is 2025-02-23T22:21:22.341Z' }, { role: 'user', content: 'Who won the 2016 US presidential election?' } ], tools: undefined, tool_choice: undefined, functions: undefined, function_call: undefined }, statusCode: 401, responseHeaders: { 'alt-svc': 'h3=":443"; ma=86400', 'cf-cache-status': 'DYNAMIC', 'cf-ray': '916a9bc6ab8967a5-SJC', connection: 'keep-alive', 'content-length': '496', 'content-type': 'application/json; charset=utf-8', date: 'Sun, 23 Feb 2025 22:21:22 GMT', server: 'cloudflare', 'set-cookie': '_cfuvid=Yzi0onHHHypaoZTfi1CXw63mnIZT6QfotRlWFXSDcYk-1740349282375-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', vary: 'Origin', 'x-content-type-options': 'nosniff', 'x-request-id': 'req_f1f10fd24bb4c6b25a037e5e1083db49' }, responseBody: '{\n "error": {\n "message": "You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",\n "type": "invalid_request_error",\n "param": null,\n "code": null\n }\n}\n', isRetryable: false, data: { error: { message: 'You didn\'t provide an API key. You need to provide your API key in an Authorization header using *** (i.e. Authorization: *** or as the password field (with blank username) if you\'re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.', type: 'invalid_request_error', param: null, code: null } } }
messages,
...argsForExecute,
experimental_telemetry: this.experimental_telemetry,
experimental_telemetry: {
...this.experimental_telemetry,
...telemetryOptions,
},
});
}

Expand All @@ -173,6 +177,7 @@ export class MastraLLM extends MastraLLMBase {
runId,
temperature,
toolChoice = 'auto',
telemetryOptions,
}: LLMTextObjectOptions<T>) {
const model = this.#model;

Expand Down Expand Up @@ -228,7 +233,10 @@ export class MastraLLM extends MastraLLMBase {
...argsForExecute,
output: output as any,
schema,
experimental_telemetry: this.experimental_telemetry,
experimental_telemetry: {
...this.experimental_telemetry,
...telemetryOptions,
},
});
}

Expand All @@ -242,6 +250,7 @@ export class MastraLLM extends MastraLLMBase {
runId,
temperature,
toolChoice = 'auto',
telemetryOptions,
}: LLMInnerStreamOptions) {
const model = this.#model;
this.logger.debug(`[LLM] - Streaming text`, {
Expand Down Expand Up @@ -298,7 +307,10 @@ export class MastraLLM extends MastraLLMBase {
return await streamText({
messages,
...argsForExecute,
experimental_telemetry: this.experimental_telemetry,
experimental_telemetry: {
...this.experimental_telemetry,
...telemetryOptions,
},
});
}

Expand All @@ -313,6 +325,7 @@ export class MastraLLM extends MastraLLMBase {
runId,
temperature,
toolChoice = 'auto',
telemetryOptions,
}: LLMStreamObjectOptions<T>) {
const model = this.#model;
this.logger.debug(`[LLM] - Streaming structured output`, {
Expand Down Expand Up @@ -384,7 +397,10 @@ export class MastraLLM extends MastraLLMBase {
...argsForExecute,
output: output as any,
schema,
experimental_telemetry: this.experimental_telemetry,
experimental_telemetry: {
...this.experimental_telemetry,
...telemetryOptions,
},
});
}

Expand All @@ -398,6 +414,7 @@ export class MastraLLM extends MastraLLMBase {
runId,
output = 'text',
temperature,
telemetryOptions,
}: LLMStreamOptions<Z> = {},
): Promise<GenerateReturn<Z>> {
const msgs = this.convertToMessages(messages);
Expand All @@ -422,6 +439,7 @@ export class MastraLLM extends MastraLLMBase {
tools,
convertedTools,
runId,
telemetryOptions,
})) as unknown as GenerateReturn<Z>;
}

Expand All @@ -436,6 +454,7 @@ export class MastraLLM extends MastraLLMBase {
runId,
output = 'text',
temperature,
telemetryOptions,
}: LLMStreamOptions<Z> = {},
) {
const msgs = this.convertToMessages(messages);
Expand All @@ -450,6 +469,7 @@ export class MastraLLM extends MastraLLMBase {
convertedTools,
runId,
temperature,
telemetryOptions,
})) as unknown as StreamReturn<Z>;
}

Expand All @@ -463,6 +483,7 @@ export class MastraLLM extends MastraLLMBase {
convertedTools,
runId,
temperature,
telemetryOptions,
})) as unknown as StreamReturn<Z>;
}
}

0 comments on commit dd307cc

Please sign in to comment.