openai.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import type ReconnectingWebSocket from 'reconnecting-websocket'
  2. import { http } from '@uozi-admin/request'
  3. import ws from '@/lib/websocket'
  4. export interface ChatComplicationMessage {
  5. role: string
  6. content: string
  7. name?: string
  8. }
  9. export interface CodeCompletionRequest {
  10. context: string // Context of the code
  11. code: string // Code before the cursor
  12. suffix?: string // Code after the cursor
  13. language?: string // Programming language
  14. position?: { // Cursor position
  15. row: number
  16. column: number
  17. }
  18. }
  19. export interface CodeCompletionResponse {
  20. code: string // Completed code
  21. }
  22. const openai = {
  23. get_record(path: string) {
  24. return http.get(`/chatgpt/history`, { params: { path } })
  25. },
  26. store_record(data: { file_name?: string, messages?: ChatComplicationMessage[] }) {
  27. return http.post('/chatgpt_record', data)
  28. },
  29. code_completion() {
  30. return ws('/api/code_completion') as ReconnectingWebSocket
  31. },
  32. get_code_completion_enabled_status() {
  33. return http.get<{ enabled: boolean }>('/code_completion/enabled')
  34. },
  35. }
  36. export default openai