Skip to content

Commit

Permalink
Merge branch 'main' into granite_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-desmond authored Dec 12, 2024
2 parents a8fa111 + 4fff94a commit eb52363
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/agents/bee/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ You must skip the instruction lines Function Name, Function Input and Function O
Message: User's message. You never use this instruction line.
{{^tools.length}}
Thought: A single-line plan of how to answer the user's message. It must be immediately followed by Final Answer.
Thought: A single-line plan of how to answer the user's message, including an explanation of the reasoning behind it. It must be immediately followed by Final Answer.
{{/tools.length}}
{{#tools.length}}
Thought: A single-line step-by-step plan of how to answer the user's message. You can use the available functions defined above. This instruction line must be immediately followed by Function Name if one of the available functions defined above needs to be called, or by Final Answer. Do not provide the answer here.
Thought: A single-line step-by-step plan of how to answer the user's message, including an explanation of the reasoning behind it. You can use the available functions defined above. This instruction line must be immediately followed by Function Name if one of the available functions defined above needs to be called, or by Final Answer. Do not provide the answer here.
Function Name: Name of the function. This instruction line must be immediately followed by Function Input.
Function Input: Function parameters. Empty object is a valid parameter.
Function Output: Output of the function in JSON format.
Expand Down Expand Up @@ -86,7 +86,7 @@ When the message is unclear or you need more information from the user, ask in F
# Your capabilities
Prefer to use these capabilities over functions.
- You understand these languages: English, Spanish, French.
- You can translate and summarize, even long documents.
- You can translate, analyze and summarize, even long documents.
# Notes
- If you don't know the answer, say that you don't know.
Expand Down
7 changes: 5 additions & 2 deletions src/instrumentation/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/

import { BAMChatLLMInputConfig } from "@/adapters/bam/chat.js";
import { getProp } from "@/internals/helpers/object.js";
import { BaseLLM } from "@/llms/base.js";
import { isFunction } from "remeda";

export function assertLLMWithMessagesToPromptFn(instance: object): instance is BaseLLM<any, any> & {
messagesToPrompt: BAMChatLLMInputConfig["messagesToPrompt"];
} {
return isFunction(getProp(instance, ["messagesToPrompt"])) && instance instanceof BaseLLM;
return Boolean(
instance instanceof BaseLLM &&
"messagesToPrompt" in instance &&
isFunction(instance.messagesToPrompt),
);
}
38 changes: 33 additions & 5 deletions src/llms/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,40 @@ export abstract class BaseLLM<
async (run) => {
const cacheEntry = await this.createCacheAccessor(input, options);

const tokens: TOutput[] = [];
for await (const token of cacheEntry.value || this._stream(input, options ?? {}, run)) {
tokens.push(token);
emit(token);
try {
await run.emitter.emit("start", { input, options });

const tokenEmitter = run.emitter.child({ groupId: "tokens" });
const chunks: TOutput[] = [];
const controller = createAbortController(options?.signal);

for await (const chunk of cacheEntry.value ||
this._stream(input, { ...options, signal: controller.signal }, run)) {
if (controller.signal.aborted) {
continue;
}

chunks.push(chunk);
await tokenEmitter.emit("newToken", {
value: chunk,
callbacks: { abort: () => controller.abort() },
});
emit(chunk);
}
const result = this._mergeChunks(chunks);
await run.emitter.emit("success", { value: result });
cacheEntry.resolve(chunks);
} catch (error) {
await run.emitter.emit("error", { input, error, options });
await cacheEntry.reject(error);
if (error instanceof LLMError) {
throw error;
} else {
throw new LLMError(`LLM has occurred an error.`, [error]);
}
} finally {
await run.emitter.emit("finish", null);
}
cacheEntry.resolve(tokens);
},
).middleware(INSTRUMENTATION_ENABLED ? createTelemetryMiddleware() : doNothing());
});
Expand Down
2 changes: 1 addition & 1 deletion src/tools/python/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface PythonToolOptions extends BaseToolOptions {
export class PythonTool extends Tool<PythonToolOutput, PythonToolOptions> {
name = "Python";
description = [
"Run Python and/or shell code and return the console output. Use for isolated calculations, computations, data or file manipulation but still prefer assistant's capabilities and NEVER use for text summarization.",
"Run Python and/or shell code and return the console output. Use for isolated calculations, computations, data or file manipulation but still prefer assistant's capabilities (IMPORTANT: Do not use for text analysis or summarization).",
"Files provided by the user, or created in a previous run, will be accessible if and only if they are specified in the input. It is necessary to always print() results.",
"The following shell commands are available:",
"Use ffmpeg to convert videos.",
Expand Down

0 comments on commit eb52363

Please sign in to comment.