Skip to content

Commit

Permalink
Tool call serve context (#468)
Browse files Browse the repository at this point in the history
* Serve context in tool call

* Add changeset
  • Loading branch information
michaelfester authored Dec 3, 2024
1 parent ac217a3 commit d19c870
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fluffy-crabs-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@markprompt/react": patch
---

Serve context in tool call
32 changes: 32 additions & 0 deletions examples/with-embed/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>
<head>
<title>Embed Demo | Markprompt</title>
<style>
body {
background-color: #fafafa;
overflow: hidden;
}
#markprompt-container {
border: 1px solid #e5e5e5;
border-radius: 0.5rem;
overflow: hidden;
height: 80%;
max-height: 600px;
width: 80%;
max-width: 800px;
}
</style>
</head>
<body
style="
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
"
>
<div id="markprompt-container"></div>
<script src="https://markprompt.com/embed/<YOUR-EMBED-CODE>" />
</body>
</html>
4 changes: 3 additions & 1 deletion packages/react/src/chat/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface ChatViewTool {
* OpenAI. Should validate the JSON for correctness as OpenAI can hallucinate
* arguments. Must return a string to feed the result back into OpenAI.
**/
call: (args: string) => Promise<string>;
call: (args: string, context?: { threadId: string }) => Promise<string>;
/**
* Whether user needs to confirm a call to this function or function calls
* will be executed right away.
Expand Down Expand Up @@ -570,8 +570,10 @@ export const createChatStore = ({
status: 'loading',
});

const threadId = get().threadId!;
const result = await tool.call(
tool_call.function?.arguments || '{}',
{ threadId },
);

get().setToolCallById(tool_call.id!, {
Expand Down

0 comments on commit d19c870

Please sign in to comment.