(ctx context.Context, model string, teamID string)
| 239 | } |
| 240 | |
| 241 | func (i *imlLocalModelController) initAILocalService(ctx context.Context, model string, teamID string) (func() error, error) { |
| 242 | catalogueInfo, err := i.catalogueModule.DefaultCatalogue(ctx) |
| 243 | if err != nil { |
| 244 | return nil, err |
| 245 | } |
| 246 | serviceId := uuid.NewString() |
| 247 | prefix := fmt.Sprintf("/%s", serviceId[:8]) |
| 248 | providerId := ai_provider_local.ProviderLocal |
| 249 | err = i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 250 | _, err = i.serviceModule.Create(ctx, teamID, &service_dto.CreateService{ |
| 251 | Id: serviceId, |
| 252 | Name: model, |
| 253 | Prefix: prefix, |
| 254 | Description: "Auto generated service for AI model " + model, |
| 255 | ServiceType: "public", |
| 256 | State: "deploying", |
| 257 | Catalogue: catalogueInfo.Id, |
| 258 | ApprovalType: "auto", |
| 259 | Kind: "ai", |
| 260 | Provider: &providerId, |
| 261 | Model: &model, |
| 262 | }) |
| 263 | if err != nil { |
| 264 | return err |
| 265 | } |
| 266 | return i.module.SaveCache(ctx, model, serviceId) |
| 267 | }) |
| 268 | |
| 269 | return func() error { |
| 270 | path := fmt.Sprintf("/%s/chat/completions", strings.Trim(prefix, "/")) |
| 271 | timeout := 300000 |
| 272 | retry := 0 |
| 273 | aiPrompt := &ai_api_dto.AiPrompt{ |
| 274 | Variables: []*ai_api_dto.AiPromptVariable{}, |
| 275 | Prompt: "", |
| 276 | } |
| 277 | aiModel := &ai_api_dto.AiModel{ |
| 278 | Id: model, |
| 279 | Config: ai_provider_local.LocalConfig, |
| 280 | Provider: providerId, |
| 281 | Type: "local", |
| 282 | } |
| 283 | name := "Demo AI API" |
| 284 | description := "This is a demo that shows you how to use a Chat API." |
| 285 | apiId := uuid.NewString() |
| 286 | err = i.aiAPIModule.Create( |
| 287 | ctx, |
| 288 | serviceId, |
| 289 | &ai_api_dto.CreateAPI{ |
| 290 | Id: apiId, |
| 291 | Name: name, |
| 292 | Path: path, |
| 293 | Description: description, |
| 294 | Disable: false, |
| 295 | AiPrompt: aiPrompt, |
| 296 | AiModel: aiModel, |
| 297 | Timeout: timeout, |
| 298 | Retry: retry, |
no test coverage detected