Skip to content

Commit

Permalink
improve cohere input detection (#8)
Browse files Browse the repository at this point in the history
* improve cohere input detection

* bump version

* remove cohere invalid format test, since cohere is so aggressive at matching the output format even when there are no matching instructions
  • Loading branch information
jrhizor authored Oct 18, 2023
1 parent f007ac0 commit cdac05b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elelem",
"version": "0.0.4",
"version": "0.0.5",
"description": "Simple, opinionated, JSON-typed, and traced LLM framework for TypeScript.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
26 changes: 0 additions & 26 deletions src/elelem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,32 +302,6 @@ describe("cohere", () => {
expect(result.foundingYear).toBe("1800");
expect(result.populationEstimate).toBeGreaterThan(500000);
}, 10000);

test("invalid format", async () => {
const wrapper = async () => {
return await llm.session(
"invalid-format",
{ cohere: { model: "command" } },
async (c) => {
const { result: cityDescription } = await c.cohere(
"city-description",
{
max_tokens: 100,
temperature: 0,
},
`Request ${Math.random()}\n`,
"Washington, D.C.",
capitolResponseSchema,
LangchainJsonSchemaFormatter,
);
return cityDescription;
},
);
};

// langchain formatter is worse than the one that includes examples, so this should fail with the same prompt
await expect(wrapper()).rejects.toThrowError(ElelemError);
}, 10000);
});

interface AddContext {
Expand Down
5 changes: 4 additions & 1 deletion src/elelem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,14 @@ export const elelem: Elelem = {
...modelOptions,
};

// since cohere doesn't have actual system prompts, it has trouble identifying where the input starts
const prefixedUserPrompt = `\nInput: ${userPrompt}`;

return await generate(
chatId,
combinedOptions,
systemPrompt,
userPrompt,
prefixedUserPrompt,
schema,
formatter,
backoffOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ${JSON.stringify(zodToJsonSchema(schema))}
`;
};

export const akerExampleFormatter: ElelemFormatter = <T>(
export const FakerExampleFormatter: ElelemFormatter = <T>(
schema: ZodType<T>,
) => {
return `
Expand Down

0 comments on commit cdac05b

Please sign in to comment.