Skip to content

Commit

Permalink
plugin content
Browse files Browse the repository at this point in the history
  • Loading branch information
v1xingyue committed Jan 14, 2025
1 parent e4219d6 commit 251ba3b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
72 changes: 70 additions & 2 deletions docs/first-plugin-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,74 @@ export interface Content {

在 Content 中,指定 其他 Action 的ID ,就可以把消息路由给其他的插件 Action 模块。

### Provider 调用:
一个 Action 的大致流程:

`eliza`中 Provider 提供一个通用的 get 方法用于对外输出数据。
```ts
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}

const context = composeContext({
state,
template: chargeTemplate,
});

const chargeDetails = await generateObject({
runtime,
context,
modelClass: ModelClass.LARGE,
schema: ChargeSchema,
});

callback(
{
text: "Hello world!!!!",
},[]);
```

### Provider 调用

`eliza`中 Provider 提供一个通用的 get 方法用于对外输出数据。

`plugin` 的 Action 调用过程中,会检查 state 参数,如果没有,那么通过 runtime 构建:

```ts
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}
```

构建过程中,需要注入所有注册了的Provider的 Get 数据

```ts
const [resolvedEvaluators, resolvedActions, providers] =
await Promise.all([
Promise.all(evaluatorPromises),
Promise.all(actionPromises),
getProviders(this, message, initialState),
]);
```

getProviders 方法:

```ts
export async function getProviders(
runtime: IAgentRuntime,
message: Memory,
state?: State
) {
const providerResults = (
await Promise.all(
runtime.providers.map(async (provider) => {
return await provider.get(runtime, message, state);
})
)
).filter((result) => result != null && result !== "");

return providerResults.join("\n");
}
```
2 changes: 1 addition & 1 deletion packages/page/src/components/MarkdownContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ReactElement } from "react";
import { ReactNode, type ReactElement, useState } from "react";
import ReactMarkdown from "react-markdown";
import type { Components } from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
Expand Down

0 comments on commit 251ba3b

Please sign in to comment.