File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22from openai import OpenAI
33from fastapi import HTTPException
44
5- def gpt_service (prompt ):
5+ def gpt_service (prompt , token ):
66
77 try :
8- client = OpenAI (api_key = os . environ . get ( "OPENAI_API_KEY" ) )
8+ client = OpenAI (api_key = token )
99 chat_completion = client .chat .completions .create (
1010 messages = [
1111 {
Original file line number Diff line number Diff line change 55
66class IaCBasicInput (BasicInput ):
77 input :str
8- service : Optional [ str ] = 'terraform'
8+ token : str
99
1010 @validator ("input" )
1111 def validate_input (cls , value ):
1212 if not value :
1313 raise ValueError ("Input cannot be empty." )
1414 return value
1515
16- @validator ("service" )
17- def validate_service (cls , value ):
18- allowed_services = ['terraform' ]
19- if value not in allowed_services :
20- raise ValueError (f"Service must be one of { allowed_services } ." )
21- return value
16+
2217
2318class IaCBugfixInput (BasicInput ):
2419 bug_description :str
25- version :str = 'latest'
26- service :Optional [str ] = 'terraform'
20+ token :str
2721
2822 @validator ("bug_description" )
2923 def validate_bug_description (cls , value ):
3024 if not value :
3125 raise ValueError ("Bug description cannot be empty." )
3226 return value
3327
34- @validator ("version" )
35- def validate_version (cls , value ):
36- if not value :
37- raise ValueError ("Version cannot be empty." )
38- return value
39-
40- @validator ("service" )
41- def validate_service (cls , value ):
42- allowed_services = ['terraform' ]
43- if value not in allowed_services :
44- raise ValueError (f"Service must be one of { allowed_services } ." )
45- return value
28+
4629
4730class IaCInstallationInput (BaseModel ):
4831 os :str = "Ubuntu"
Original file line number Diff line number Diff line change 55def IaC_basics_generator (input : IaCBasicInput ) -> str :
66
77 prompt = f"""
8- Write a robust answer about { input .service } ,
9- focusing on the latest update of { input .service } and based on this question:{ input .input } ,
10- minimun length of answer is { input .min_tokens } and maximum length is { input .max_tokens }
11-
8+ { input .input }
129 """
1310 return prompt
1411
1512
1613def IaC_bugfix_generator (input : IaCBugfixInput ) -> str :
1714
1815 prompt = f"""
19- Write a clear answer to debug { input .service }
20- focusing on the version { input .version } of { input .service } and based on this bug:{ input .bug_description } ,
21- generate a correct code that help us to solve this bug.
22- minimum length of answer is { input .min_tokens } and maximum length is { input .max_tokens }
16+ { input .bug_description }
2317
2418 """
2519 return prompt
Original file line number Diff line number Diff line change @@ -38,15 +38,15 @@ async def IaC_basic_generation(request:IaCBasicInput) -> Output:
3838 if os .environ .get ("TEST" ):
3939 return Output (output = 'Terraform developed by hashicorp and it is very usefull' )
4040 generated_prompt = IaC_basics_generator (request )
41- output = gpt_service (generated_prompt )
41+ output = gpt_service (generated_prompt , request . token )
4242 return Output (output = output )
4343
4444@app .post ("/api/IaC-bugfix/" )
4545async def IaC_bugfix_generation (request :IaCBugfixInput ) -> Output :
4646 if os .environ .get ("TEST" ):
4747 return Output (output = 'fix this bug by adding x to the y' )
4848 generated_prompt = IaC_bugfix_generator (request )
49- output = gpt_service (generated_prompt )
49+ output = gpt_service (generated_prompt , request . token )
5050 return Output (output = output )
5151
5252
You can’t perform that action at this time.
0 commit comments