Skip to content

Conversation

gustavocidornelas
Copy link
Contributor

@gustavocidornelas gustavocidornelas commented Aug 22, 2024

Summary

  • Introduces tracing to the TS SDK.
  • In TS, the traced functions should be wrapped by the higher-order function trace. E.g.,
import { trace } from 'openlayer/lib/tracing/tracer'

function preparePrompt(input: string): { role: string; content: string }[] {
   return [
     { role: 'system', content: 'You are a helpful assistant.' },
     { role: 'user', content: input },
  ];
 }
const tracedPreparePrompt = trace(preparePrompt)
  • Introduces the OpenAI tracer, which follows a similar syntax to the Python SDK one. Namely:
import { traceOpenAI } from 'openlayer/lib/integrations/openAiTracer';

const client = traceOpenAI(new OpenAI());

async function main(input: string): Promise<string> {
  const response = await client.chat.completions.create({
    stream: true,
    model: 'gpt-4o',
    messages: [
      { role: 'user', content: input},
    ]
  });
  }
  return '';
}

// Run the main function
main('Are you an AI or an actual human?').catch(console.error);

@gustavocidornelas gustavocidornelas marked this pull request as ready for review September 19, 2024 19:01
@gustavocidornelas gustavocidornelas changed the title feat: tracing lib [wip] feat: tracing lib Sep 19, 2024
@gustavocidornelas gustavocidornelas merged commit 2c06424 into main Sep 19, 2024
2 checks passed
@gustavocidornelas gustavocidornelas deleted the cid/tracing branch September 19, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants