Skip to content

Commit

Permalink
Bump AI.JSX version, restore render logging
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalas committed Aug 18, 2023
1 parent 45158c4 commit e1a75e9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/ai-jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"repository": "fixie-ai/ai-jsx",
"bugs": "https://github.com/fixie-ai/ai-jsx/issues",
"homepage": "https://ai-jsx.com",
"version": "0.9.1",
"version": "0.9.2",
"volta": {
"extends": "../../package.json"
},
Expand Down
18 changes: 6 additions & 12 deletions packages/ai-jsx/src/core/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,16 @@ export class CombinedLogger extends LogImplementation {
super();
}

log(
level: LogLevel,
element: Element<any>,
renderId: string,
metadataOrMessage: string | object,
message?: string | undefined
): void {
this.loggers.forEach((l) => l.log(level, element, renderId, metadataOrMessage, message));
log(...args: Parameters<LogImplementation['log']>): void {
this.loggers.forEach((l) => l.log(...args));
}

logException(element: Element<object>, renderId: string, exception: unknown): void {
this.loggers.forEach((l) => l.logException(element, renderId, exception));
logException(...args: Parameters<LogImplementation['logException']>): void {
this.loggers.forEach((l) => l.logException(...args));
}

setAttribute(element: Element<any>, renderId: string, key: string, value: string): void {
this.loggers.forEach((l) => l.setAttribute(element, renderId, key, value));
setAttribute(...args: Parameters<LogImplementation['setAttribute']>): void {
this.loggers.forEach((l) => l.setAttribute(...args));
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/ai-jsx/src/core/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,19 @@ async function* renderStream(
const logImpl = renderingContext.getContext(LoggerContext);
const renderId = uuidv4();
try {
/**
* This approach is pretty noisy because there are many internal components about which the users don't care.
* For instance, if the user writes <ChatCompletion>, that'll generate a bunch of internal helpers to
* locate + call the model provider, etc.
*
* To get around this, maybe we want components to be able to choose the loglevel used for their rendering.
*/
logImpl.log('debug', renderable, renderId, 'Start rendering element');
const finalResult = yield* renderingContext.render(
renderable.render(renderingContext, new BoundLogger(logImpl, renderId, renderable), appendOnly),
recursiveRenderOpts
);
logImpl.log('debug', renderable, renderId, { finalResult }, 'Finished rendering element');
return finalResult;
} catch (ex) {
logImpl.logException(renderable, renderId, ex);
Expand Down
8 changes: 7 additions & 1 deletion packages/docs/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## 0.9.1
## 0.9.2

- In the [OpenTelemetry integration](./guides/observability.md#opentelemetry-integration):
- Add prompt/completion attributes with token counts for `<OpenAIChatModel>`. This replaces the `tokenCount` attribute added in 0.9.1.
- By default, only emit spans for `async` components.

## [0.9.1](https://github.com/fixie-ai/ai-jsx/commit/0d2e6d8ecd1c75b457d0d6c76ff854c9145a9f5f)

- Add `tokenCount` field to [OpenTelemetry-emitted spans](./guides/observability.md#opentelemetry-integration). Now, if you're emitting via OpenTelemetry (e.g. to DataDog), the spans will tell you how many tokens each component resolved to. This is helpful for answering quetsions like "how big is my system message?".

Expand Down
4 changes: 1 addition & 3 deletions packages/examples/test/core/completion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ describe('OpenTelemetry', () => {
});
sdk.start();

afterAll(async () => {
await sdk.shutdown();
});
afterAll(() => sdk.shutdown());

beforeEach(() => {
memoryExporter.reset();
Expand Down

0 comments on commit e1a75e9

Please sign in to comment.