Skip to content

Commit

Permalink
fix: use sample
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 3, 2023
1 parent 3732b41 commit 823e01d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion utils/3rd/bilibili.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sample } from "lodash";
import { sample } from "../fp";

const run = async (bvId: string) => {
const requestUrl = `https://api.bilibili.com/x/web-interface/view?bvid=${bvId}`;
Expand Down
6 changes: 1 addition & 5 deletions utils/OpenAIResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ReconnectInterval,
} from "eventsource-parser";
import { checkOpenaiApiKey } from "./3rd/openai";
import { sample } from "./fp";

// TODO: maybe chat with video?
export type ChatGPTAgent = "user" | "system" | "assistant";
Expand All @@ -25,11 +26,6 @@ export interface OpenAIStreamPayload {
n: number;
}

const sample = (arr: any[] = []) => {
const len = arr === null ? 0 : arr.length;
return len ? arr[Math.floor(Math.random() * len)] : undefined;
};

function formatResult(result: any) {
const answer = result.choices[0].message?.content || "";
if (answer.startsWith("\n\n")) {
Expand Down
4 changes: 4 additions & 0 deletions utils/fp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const sample = (arr: any[] = []) => {
const len = arr === null ? 0 : arr.length;
return len ? arr[Math.floor(Math.random() * len)] : undefined;
};

1 comment on commit 823e01d

@vercel
Copy link

@vercel vercel bot commented on 823e01d Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.