Skip to content

Commit 95ee377

Browse files
committed
fix(token): fix openai token input for basic and bugfix sections
1 parent 4ee06d7 commit 95ee377

File tree

4 files changed

+10
-33
lines changed

4 files changed

+10
-33
lines changed

app/gpt_services.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from openai import OpenAI
33
from 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
{

app/models/terraform_models.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,27 @@
55

66
class 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

2318
class 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

4730
class IaCInstallationInput(BaseModel):
4831
os:str = "Ubuntu"

app/prompt_generators.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@
55
def 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

1613
def 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

app/routes/terraform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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/")
4545
async 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

0 commit comments

Comments
 (0)