Skip to content

Conversation

@bfollington
Copy link
Contributor

@bfollington bfollington commented Jun 25, 2024

Introduces a small utility function to trivially generate data based off of a description, some input data and a schema it should adhere to. Should be useful for implementing a prototype of search (cc @seefeldb).

import { generateData, LLMClient } from "@commontools/llm-client";

const client = new LLMClient({
  serverUrl: LLM_SERVER_URL,
  tools: [],
  system: `Generate dummy data as JSON as per the provided spec. Use the input to imagine what an API response would look like for a request.`,
});

const test = await generateData(
  client,
  "generate 3 user profiles",
  { name: "John Doe" },
  {
    type: "array",
    items: {
      type: "object",
      properties: {
        name: { type: "string" },
        email: { type: "string" },
        age: { type: "number" },
        role: { type: "string" },
        birthday: { type: "string" },
        favoriteColor: { type: "string" },
      },
    },
  },
);

console.log(test);

This produces:

[
    {
        "name": "John Doe",
        "email": "john.doe@example.com",
        "age": 35,
        "role": "Software Engineer",
        "birthday": "1988-03-15",
        "favoriteColor": "blue"
    },
    {
        "name": "Jane Smith",
        "email": "jane.smith@example.com",
        "age": 28,
        "role": "Product Manager",
        "birthday": "1995-07-22",
        "favoriteColor": "purple"
    },
    {
        "name": "Alex Johnson",
        "email": "alex.johnson@example.com",
        "age": 42,
        "role": "Marketing Director",
        "birthday": "1981-11-03",
        "favoriteColor": "green"
    }
]

@bfollington bfollington requested a review from seefeldb June 25, 2024 01:21
@bfollington bfollington marked this pull request as ready for review June 25, 2024 01:21
@seefeldb seefeldb merged commit 537c50d into main Jun 25, 2024
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.

3 participants