Skip to content

Commit

Permalink
fix: cf worker
Browse files Browse the repository at this point in the history
  • Loading branch information
sdip15fa committed Feb 28, 2024
1 parent 60eb8fa commit ec02aee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cf-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"wrangler": "^3.0.0"
},
"dependencies": {
"@cloudflare/ai": "^1.0.50"
"@cloudflare/ai": "^1.0.52"
}
}
36 changes: 17 additions & 19 deletions cf-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,23 @@ export default {
return new BadRequestException('Messages must be a valid JSON array.');
}

let response: string;
// prompt - simple completion style input
if (!messages?.length) {
const simple = {
prompt: `Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n Instruction: ${prompt}\n\n Response: \n\n`,
};
response = await ai.run('@hf/thebloke/openhermes-2.5-mistral-7b-awq', simple);
} else {
const chat = {
messages: [
{
role: 'system',
content: 'Below is an instruction that describes a task. Write a response that appropriately completes the request.',
},
...messages,
],
};
response = await ai.run('@cf/meta/llama-2-7b-chat-int8', chat);
}
const chat = {
messages: [
{
role: 'system',
content: 'Below is an instruction that describes a task. Write a response that appropriately completes the request.',
},
...(messages?.length
? messages
: [
{
role: 'user',
content: prompt,
},
]),
],
};
const response = await ai.run('@cf/meta/llama-2-7b-chat-int8', chat);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
8 changes: 4 additions & 4 deletions cf-worker/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@cloudflare/ai@^1.0.50":
version "1.0.50"
resolved "https://registry.yarnpkg.com/@cloudflare/ai/-/ai-1.0.50.tgz#fadd2737daf1e1a25cda3814eff11b7cc0a3fd52"
integrity sha512-lgTrP514G9VRXEhWWDQ80gTs5latLBzoc8ouJKOEKRw6SPtEjHHrMkPv+WOAsamBOnXCjdBV63MVE2VCJ6PE7Q==
"@cloudflare/ai@^1.0.52":
version "1.0.52"
resolved "https://registry.yarnpkg.com/@cloudflare/ai/-/ai-1.0.52.tgz#1f89ad520fc18461a5b3f3db01aaf886a9a2056b"
integrity sha512-Rz7TeTOS57Gl8gzTrDdW6vPAuEX+4T1wx/+w5C9yDaREPxlFjAJBFYMAfMr7z96c3QYfLLekaV9kjtJJUdQSRQ==

"@cloudflare/kv-asset-handler@^0.2.0":
version "0.2.0"
Expand Down

0 comments on commit ec02aee

Please sign in to comment.