Skip to content

Commit 9051ed8

Browse files
authored
Merge pull request #2 from lxfater/feature/add_temperature_and_topP
Add temperature, topP to GenerateTextRequest
2 parents 56c84de + 697f28f commit 9051ed8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/headless/src/types/worker_message.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export type GenerateTextRequest = {
1515
stopTexts: string[],
1616
maxTokens: number,
1717
assistantRoleName: string,
18+
temperature: number,
19+
top_p: number,
20+
1821
}
1922

2023
export type GenerateTextResponse = {

packages/headless/src/worker/llm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class LLMInstanceScope {
198198
}
199199

200200
async generate(request: GenerateTextRequest, cb: GenerateTextCallback) {
201-
const { conversation, maxTokens, assistantRoleName, stopTexts } = request;
201+
const { conversation, maxTokens, assistantRoleName, stopTexts, temperature, top_p } = request;
202202
const tokens = await this.getTokens(conversation, maxTokens);
203203
tokens.push(...(await this.tokenizer.encodeIds(`${assistantRoleName}:`)));
204204
console.log("debug: ", await this.tokenizer.decodeIds(tokens));
@@ -224,7 +224,7 @@ export class LLMInstanceScope {
224224
this.forward(input, this.kvCacheLength + inputTokenLength + step)
225225
);
226226
this.tvm.endScope();
227-
const nextToken = await this.sampleTokenFromLogits(logits);
227+
const nextToken = await this.sampleTokenFromLogits(logits,temperature, top_p);
228228
logits.dispose();
229229

230230
tokens.push(nextToken);

0 commit comments

Comments
 (0)