Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid authored Dec 29, 2024
2 parents b85f042 + 278bdf8 commit 34ebe42
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
24 changes: 12 additions & 12 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!-- Use this template by filling in information and copy and pasting relevant items out of the html comments. -->
<!-- Use this template by filling in information and copying and pasting relevant items out of the HTML comments. -->

# Relates to:
# Relates to

<!-- LINK TO ISSUE OR TICKET -->

<!-- This risks section is to be filled out before final review and merge. -->
<!-- This risks section must be filled out before the final review and merge. -->

# Risks

<!--
Low, medium, large. List what kind of risks, and what could be effected.
Low, medium, large. List what kind of risks and what could be affected.
-->

# Background
Expand All @@ -25,7 +25,7 @@ Features (non-breaking change which adds functionality)
Updates (new versions of included code)
-->

<!-- This "Why" section is most relevant if there is no linked issue explaining why. If there is a related issue it might make sense to skip this why section. -->
<!-- This "Why" section is most relevant if there are no linked issues explaining why. If there is a related issue, it might make sense to skip this why section. -->
<!--
## Why are we doing this? Any context or related work?
-->
Expand All @@ -35,10 +35,10 @@ Updates (new versions of included code)
<!--
My changes do not require a change to the project documentation.
My changes require a change to the project documentation.
If a docs change is needed: I have updated the documentation accordingly.
If documentation change is needed: I have updated the documentation accordingly.
-->

<!-- Please show how you tested the PR. This will really help if the PR needs to be retested, and probably help the PR get merged quicker. -->
<!-- Please show how you tested the PR. This will really help if the PR needs to be retested and probably help the PR get merged quicker. -->

# Testing

Expand All @@ -47,7 +47,7 @@ If a docs change is needed: I have updated the documentation accordingly.
## Detailed testing steps

<!--
None, automated tests are fine.
None: Automated tests are acceptable.
-->

<!--
Expand All @@ -63,22 +63,22 @@ None, automated tests are fine.
### After
-->

<!-- If there is anything about the deploy, please make a note. -->
<!-- If there is anything about the deployment, please make a note. -->
<!--
# Deploy Notes
-->

<!--  Copy and paste commandline output. -->
<!--  Copy and paste command line output. -->
<!--
## Database changes
-->

<!--  If there is something more than the automated steps, please specifiy deploy instructions. -->
<!--  Please specify deploy instructions if there is something more than the automated steps. -->
<!--
## Deployment instructions
-->

<!-- If you are on Discord, please join https://discord.gg/ai16z and state your Discord username here for contribute role and join us in #development-feed -->
<!-- If you are on Discord, please join https://discord.gg/ai16z and state your Discord username here for the contributor role and join us in #development-feed -->
<!--
## Discord username
Expand Down
4 changes: 2 additions & 2 deletions packages/client-telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { stringToUuid } from "@elizaos/core";
import { generateMessageResponse, generateShouldRespond } from "@elizaos/core";
import { messageCompletionFooter, shouldRespondFooter } from "@elizaos/core";

import { cosineSimilarity } from "./utils";
import { cosineSimilarity, escapeMarkdown } from "./utils";
import {
MESSAGE_CONSTANTS,
TIMING_CONSTANTS,
Expand Down Expand Up @@ -692,7 +692,7 @@ export class MessageManager {
const sentMessages: Message.TextMessage[] = [];

for (let i = 0; i < chunks.length; i++) {
const chunk = chunks[i];
const chunk = escapeMarkdown(chunks[i]);
const sentMessage = (await ctx.telegram.sendMessage(
ctx.chat.id,
chunk,
Expand Down
23 changes: 23 additions & 0 deletions packages/client-telegram/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ export function cosineSimilarity(text1: string, text2: string, text3?: string):
return dotProduct / maxMagnitude;
}

export function escapeMarkdown(text: string): string {
// Don't escape if it's a code block
if (text.startsWith('```') && text.endsWith('```')) {
return text;
}

// Split the text by code blocks
const parts = text.split(/(```[\s\S]*?```)/g);

return parts.map((part, index) => {
// If it's a code block (odd indices in the split result will be code blocks)
if (index % 2 === 1) {
return part;
}
// For regular text, only escape characters that need escaping in Markdown
return part
// First preserve any intended inline code spans
.replace(/`.*?`/g, match => match)
// Then only escape the minimal set of special characters that need escaping in Markdown mode
.replace(/([*_`\\])/g, '\\$1');
}).join('');
}

/**
* Splits a message into chunks that fit within Telegram's message length limit
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/test_resources/createRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ import {
} from "./constants.ts";
import { User } from "./types.ts";

/**
* Create a runtime environment with the specified configurations.
*
* @param {Object} options - The options for creating the runtime environment.
* @param {Record<string, string> | NodeJS.ProcessEnv} [options.env] - The environment variables.
* @param {number} [options.conversationLength] - The length of the conversation.
* @param {Evaluator[]} [options.evaluators] - The array of evaluators.
* @param {Action[]} [options.actions] - The array of actions.
* @param {Provider[]} [options.providers] - The array of providers.
* @returns {Object} - An object containing the created user, session, and runtime.
*/
export async function createRuntime({
env,
conversationLength,
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/test_resources/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* Interface representing a user.
* @typedef {Object} User
* @property {string} id - The unique identifier for the user.
* @property {string} [email] - The email address of the user (optional).
* @property {string} [phone] - The phone number of the user (optional).
* @property {string} [role] - The role of the user (optional).
*/
export interface User {
id: string;
email?: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-node/src/services/video.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Service } from "@elizaos/core";
import {
IAgentRuntime,
ITranscriptionService,
IVideoService,
Media,
Service,
ServiceType,
IVideoService,
stringToUuid,
} from "@elizaos/core";
import { stringToUuid } from "@elizaos/core";
import ffmpeg from "fluent-ffmpeg";
import fs from "fs";
import path from "path";
import { tmpdir } from "os";
import path from "path";
import youtubeDl from "youtube-dl-exec";

export class VideoService extends Service implements IVideoService {
Expand Down

0 comments on commit 34ebe42

Please sign in to comment.