Skip to content

Commit

Permalink
feat: add json mode examples to cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
joschkabraun committed Feb 1, 2024
1 parent 3ecfd8f commit 763bc9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cookbook/tracing_with_openai_endpoint_directly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ async function main3() {
return result;
}

async function main4() {
const response = await openai.chat.completions.create({
model: 'gpt-4-1106-preview',
messages: [
{ role: 'system', content: 'You are a helpful assistant talking in JSON.' },
{ role: 'user', content: 'What are you?' },
],
response_format: { type: 'json_object' },
});
return response.choices[0].message.content ?? '';
}

main().then((result) => console.log(result));
main2().then((result) => console.log(result));
main3().then((result) => console.log(result));
main4().then((r) => console.log(r));
17 changes: 17 additions & 0 deletions src/cookbook/tracing_without_deployed_prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,22 @@ async function main2() {
return result;
}

async function main3() {
const completion: Completion = {
llm_configuration: {
model: 'gpt-4-1106-preview',
provider: 'openai',
model_params: { temp: 0.0, response_format: { type: 'json_object' } },
messages: [
{ role: 'system', content: 'You are a helpful assistant talking in JSON.' },
{ role: 'user', content: 'What are you?' },
],
},
metadata: { source: 'parea-js-sdk' },
};
return await p.completion(completion);
}

main().then((result) => console.log(result));
main2().then((result) => console.log(result));
main3().then((result) => console.log(result));

0 comments on commit 763bc9a

Please sign in to comment.