Skip to content

Commit

Permalink
refactor: remove unwanted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperKoza343 committed Jan 20, 2025
1 parent cd2292f commit 975bdfb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions characters/tate.character.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "tate",
"clients": ["linkedin"],
"modelProvider": "openai",
"clients": [],
"modelProvider": "anthropic",
"settings": {
"secrets": {},
"voice": {
"model": "en_US-male-medium"
}
Expand Down Expand Up @@ -52,7 +53,7 @@
]
],
"postExamples": [""],
"topics": ["Ai autonomy", "AI safety", "AI ethics", "AI governance", "AI regulation", "AI regulation", "AI regulation", "AI companies", "AI in businesses"],
"topics": [""],
"style": {
"all": [""],
"chat": [""],
Expand Down
1 change: 0 additions & 1 deletion client/src/lib/info.json

This file was deleted.

3 changes: 3 additions & 0 deletions packages/client-linkedin/src/helpers/get-random-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getRandomNumber = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IAgentRuntime } from "@elizaos/core";
const checkIfIsNumber = (val: string | number | null, ctx: z.RefinementCtx, path: string) => {
const num = Number(val);

if(isNaN(num) || !isFinite(num)) {
if(Number.isNaN(num)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Invalid number: ${val}`,
Expand All @@ -29,11 +29,11 @@ export const configSchema = z.object({
.transform((val, ctx) => checkIfIsNumber(val, ctx, 'LINKEDIN_POST_INTERVAL_MAX')),
});

export const validateEnvs = (runtime: IAgentRuntime) => {
export const validateConfig = (runtime: IAgentRuntime) => {
const LINKEDIN_ACCESS_TOKEN = runtime.getSetting("LINKEDIN_ACCESS_TOKEN");
const LINKEDIN_POST_INTERVAL_MIN = runtime.getSetting('LINKEDIN_POST_INTERVAL_MIN');
const LINKEDIN_POST_INTERVAL_MAX = runtime.getSetting("LINKEDIN_POST_INTERVAL_MAX");
console.log({LINKEDIN_POST_INTERVAL_MIN, LINKEDIN_POST_INTERVAL_MAX, LINKEDIN_ACCESS_TOKEN});

try {
const envs = configSchema.parse({
LINKEDIN_ACCESS_TOKEN,
Expand All @@ -43,7 +43,6 @@ export const validateEnvs = (runtime: IAgentRuntime) => {

return envs;
} catch (error) {
console.log(error);
if(error instanceof ZodError) {
throw new Error(`Invalid environment variables. Validating envs failed with error: ${
error.issues.map(issue => issue.path.join('.') + ': ' + issue.message).join(' , ')
Expand Down
4 changes: 2 additions & 2 deletions packages/client-linkedin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client, elizaLogger, IAgentRuntime } from "@elizaos/core";
import { validateEnvs } from "./helpers/validate-envs";
import { validateConfig } from "./helpers/validate-config";
import axios from "axios";
import { LinkedInUserInfoFetcher } from "./services/LinkedinUserInfoFetcher";
import { PostsManager } from "./services/PostsManager";
Expand All @@ -8,7 +8,7 @@ const LINKEDIN_API_URL = "https://api.linkedin.com";

export const LinkedInClient: Client = {
async start(runtime: IAgentRuntime) {
const envs = validateEnvs(runtime);
const envs = validateConfig(runtime);

const axiosInstance = axios.create({
baseURL: LINKEDIN_API_URL,
Expand Down
2 changes: 1 addition & 1 deletion packages/client-linkedin/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configSchema } from "./helpers/validate-envs";
import { configSchema } from "./helpers/validate-config";
import { z } from "zod";

export interface UserInfo {
Expand Down
5 changes: 2 additions & 3 deletions packages/client-linkedin/src/services/PostsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PostContentCreator } from "./PostContentCreator";
import { IntervalsConfig } from "../interfaces";
import { LinkedInPostPublisher } from "./LinkedinPostPublisher";
import { elizaLogger, IAgentRuntime } from "@elizaos/core";
import { getRandomNumber } from "../helpers/get-random-number";

export class PostsManager {
constructor(
Expand Down Expand Up @@ -41,9 +42,7 @@ export class PostsManager {
const minMinutes = this.intervalsConfig.LINKEDIN_POST_INTERVAL_MIN;
const maxMinutes = this.intervalsConfig.LINKEDIN_POST_INTERVAL_MAX;

const randomMinutes =
Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) +
minMinutes;
const randomMinutes = getRandomNumber(minMinutes, maxMinutes);
const delay = randomMinutes * 60 * 1000;

if (Date.now() > lastPostTimestamp + delay) {
Expand Down

0 comments on commit 975bdfb

Please sign in to comment.