Skip to content

Example or explication of how to implement jsonSchema() helper #2652

Answered by lgrammel
Rvey asked this question in Help
Discussion options

You must be logged in to vote
  let tools_from_backoffice = JSON.parse(
    '{"weather":{"description":"Get the weather","parameters":{"type":"object","properties":{"location":{"type":"string"},"temperature":{"type":"string"}},"required":["location","temperature"]}}}',
  );

  // map parameters in json schema
  Object.keys(tools_from_backoffice).forEach(tool => {
    tools_from_backoffice[tool].parameters = jsonSchema(
      tools_from_backoffice[tool].parameters,
    );
  });

  const result = await streamText({
    model: openai('gpt-4o-2024-08-06'),
    prompt: 'what is the weather in Paris?',
    tools: tools_from_backoffice,
    toolChoice: 'auto',
  });

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@lgrammel
Comment options

@Rvey
Comment options

@Rvey
Comment options

@lgrammel
Comment options

Answer selected by Rvey
@Rvey
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants