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

lucasliet / llm-telegram-bot / 17306274757

28 Aug 2025 07:45PM UTC coverage: 31.514% (-1.9%) from 33.379%
17306274757

push

github

lucasliet
feat: add Codex model support and handlers

- Implemented Codex command handling in main bot logic.
- Created CodexHandler to manage Codex requests and responses.
- Added CodexService for interaction with Codex API, including text generation and streaming responses.
- Updated KeyboardConfig to include Codex command in admin buttons.
- Enhanced model configuration to support Codex model.
- Introduced utility functions for converting message formats to Responses API.
- Added documentation for applying patches and Codex usage instructions.

47 of 82 branches covered (57.32%)

Branch coverage included in aggregate %.

41 of 263 new or added lines in 7 files covered. (15.59%)

26 existing lines in 3 files now uncovered.

1177 of 3802 relevant lines covered (30.96%)

1.43 hits per line

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

35.48
/src/util/ChatConfigUtil.ts
1
import { Content } from 'npm:@google/generative-ai';
2
import OpenAi from 'npm:openai';
3
import { ExpirableContent } from '@/repository/ChatRepository.ts';
4

5
/**
6
 * Interface for StreamReplyResponse
7
 */
8
export interface StreamReplyResponse {
9
        /** Reader for the streaming response */
10
        reader: ReadableStreamDefaultReader<Uint8Array>;
11

12
        /** Callback function to execute when the response is complete */
13
        onComplete: (completedAnswer: string) => Promise<void>;
14

15
        /** Optional function to map response body to a different format */
16
        responseMap?: (responseBody: string) => string;
17
}
18

19
/**
20
 * Message format for Responses API
21
 */
22
export type ResponsesMessage = {
23
  type: 'message';
24
  role: 'user' | 'assistant';
25
  content: Array<{ type: 'input_text' | 'output_text' | 'text'; text: string }>;
26
};
27

28
/**
1✔
29
 * Convert Gemini history format to OpenAI/GPT format
30
 *
31
 * @param history - History in Gemini format
32
 * @returns History in OpenAI format
33
 */
3✔
34
export function convertGeminiHistoryToGPT(
3✔
35
    history: ExpirableContent[],
3✔
36
): OpenAi.ChatCompletionMessageParam[] {
NEW
37
    return history.map((content) => {
×
NEW
38
        return {
×
NEW
39
            role: content.role === 'user' ? 'user' : 'assistant',
×
NEW
40
            content: content.parts.map((part) => part.text).join(' '),
×
NEW
41
        };
×
NEW
42
    });
×
43
}
5✔
44

45
/**
1✔
46
 * Convert Gemini history to Responses API message format
47
 * @param history - History in Gemini format
48
 * @returns History in Responses API message format
NEW
49
 */
×
NEW
50
export function convertGeminiHistoryToResponses(
×
NEW
51
  history: ExpirableContent[],
×
52
): ResponsesMessage[] {
NEW
53
  return history.map((content) => {
×
NEW
54
    const role = content.role === 'user' ? 'user' : 'assistant';
×
NEW
55
    const text = content.parts.map((p) => p.text).join(' ');
×
NEW
56
    const type = role === 'user' ? 'input_text' : 'output_text';
×
NEW
57
    return { type: 'message', role, content: [{ type, text }] };
×
NEW
58
  });
×
NEW
59
}
×
60

61
/**
1✔
62
 * Convert GPT messages to Responses API message format
63
 * @param messages - GPT messages
64
 * @returns Responses API messages
NEW
65
 */
×
NEW
66
export function convertGPTToResponses(
×
NEW
67
  messages: OpenAi.Chat.ChatCompletionMessageParam[],
×
68
): ResponsesMessage[] {
NEW
69
  return messages
×
NEW
70
    .map((m) => {
×
NEW
71
      const role = m.role === 'user' ? 'user' : 'assistant';
×
NEW
72
      const text = typeof m.content === 'string'
×
NEW
73
        ? m.content
×
NEW
74
        : Array.isArray(m.content)
×
NEW
75
          ? m.content.map((c) => (c as any).text || '').join('')
×
NEW
76
          : '';
×
NEW
77
      const type = role === 'user' ? 'input_text' : 'output_text';
×
NEW
78
      return { type: 'message', role, content: [{ type, text }] } as ResponsesMessage;
×
NEW
79
    });
×
UNCOV
80
}
×
81

82
/**
1✔
83
 * Remove expiration-related properties from history objects
84
 *
85
 * @param history - History with expiration information
86
 * @returns History without expiration information
87
 */
×
88
export function removeExpirationFromHistory(
×
NEW
89
    history: ExpirableContent[],
×
90
): Content[] {
NEW
91
    return history.map(({ createdAt: _, ...content }) => content);
×
92
}
×
93

94
/**
1✔
95
 * Replace configuration variables in a Gemini prompt template
96
 *
97
 * @param chatName - Name of the chat service
98
 * @param model - Model name
99
 * @param maxTokens - Maximum tokens for generation
100
 * @returns Modified prompt with updated values
101
 */
3✔
102
export function getSystemPrompt(
3✔
103
    chatName: string,
3✔
104
    model: string,
3✔
105
    maxTokens: number,
3✔
106
): string {
107
    return systemPrompt(chatName, model, maxTokens);
5✔
108
}
5✔
109

110
/**
1✔
111
 * Builds an assistant message for Responses API
112
 * @param text - Assistant text content
113
 * @returns Responses API assistant message
NEW
114
 */
×
NEW
115
export function buildAssistantMessage(text: string): ResponsesMessage {
×
NEW
116
  return { type: 'message', role: 'assistant', content: [{ type: 'output_text', text }] };
×
UNCOV
117
}
×
118

119
const systemPrompt = (chatName: string, model: string, maxTokens: number) =>
3✔
120
    `
3✔
121
        Você é ${chatName}, um modelo de linguagem de IA muito prestativo. Está usando o modelo ${model} 
5✔
122
        e está hospedado em um bot do cliente de mensagens Telegram.
123
        Então tentará manter suas respostas curtas e diretas para obter melhores resultados 
124
        com o máximo de ${maxTokens} tokens de saída,
5✔
125
        Pode usar à vontade as estilizações de texto e emojis para tornar a conversa mais agradável e natural.
126

127
        Deve sempre respeitar a linguagem de marcação Markdown, evitando abrir marcações sem fecha-las.
128

129
        Caso tenha buscado informações atualizadas na internet, indique suas fontes de informação.
130
    `;
3✔
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