• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 12776988579

14 Jan 2025 09:48PM UTC coverage: 48.037% (-0.1%) from 48.168%
12776988579

Pull #10529

github

web-flow
Merge 3f194b364 into fc164f9cc
Pull Request #10529: Add contest bot webhook

1313 of 3050 branches covered (43.05%)

Branch coverage included in aggregate %.

6 of 35 new or added lines in 6 files covered. (17.14%)

1 existing line in 1 file now uncovered.

2591 of 5077 relevant lines covered (51.03%)

34.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.5
/libs/model/src/services/openai/parseBotCommand.ts
1
import { OpenAI } from 'openai';
2
import {
3
  ChatCompletionMessage,
4
  ChatCompletionTool,
5
} from 'openai/resources/index.mjs';
6
import { config } from '../../config';
7

8
export type ContestMetadataResponse = {
9
  contestName: string;
10
  payoutStructure: number[];
11
  voterShare: number;
12
  image_url: string;
13
  tokenAddress: string;
14
};
15

16
const system_prompt: ChatCompletionMessage = {
24✔
17
  role: 'assistant',
18
  content: `you are a data extraction system to understand intents of the following style of message: \n
19
    "hey @contestbot create a contest with the token 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
20
    with 20% of prize amount allocated to voters and the rest going to one winner.
21
    The contest title is “Submit your best artwork for our token”.
22
    Use the following image https://test.com/test.png" \n
23
    This message should result in the following parameters: \n
24
    {
25
"contestName": "Submit your best artwork for our token",
26
  "payoutStructure": [100],
27
  "voterShare": 20,
28
  "image_url": "https://test.com/test.png",
29
  "tokenAddress": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
30
}`,
31
};
32

33
const tools: ChatCompletionTool[] = [
24✔
34
  {
35
    type: 'function',
36
    function: {
37
      name: 'parse_data',
38
      parameters: {
39
        type: 'object',
40
        properties: {
41
          contestName: { type: 'string' },
42
          payoutStructure: { type: 'array', items: { type: 'number' } },
43
          voterShare: { type: 'number' },
44
          image_url: { type: 'string' },
45
          tokenAddress: { type: 'string' },
46
        },
47
      },
48
    },
49
  },
50
];
51

52
export const parseBotCommand = async (
24✔
53
  command: string,
54
): Promise<ContestMetadataResponse> => {
UNCOV
55
  const openai = new OpenAI({
×
56
    organization: config.OPENAI.ORGANIZATION,
57
    apiKey: config.OPENAI.API_KEY,
58
  });
59

60
  const response = await openai.chat.completions.create({
×
61
    model: 'gpt-4-turbo',
62
    messages: [
63
      system_prompt,
64
      {
65
        role: 'user',
66
        content: command,
67
      },
68
    ],
69
    tools,
70
  });
71

72
  const data = JSON.parse(
×
73
    response.choices[0].message.tool_calls![0].function.arguments,
74
  );
75

76
  return {
×
77
    contestName: data.contestName,
NEW
78
    payoutStructure: data.payoutStructure.map((n: number) => Math.floor(n)),
×
79
    voterShare: data.voterShare,
80
    image_url: data.image_url,
81
    tokenAddress: data.tokenAddress,
82
  };
83
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc