File size: 984 Bytes
a8a595d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time

from grazie.api.client.chat.prompt import ChatPrompt
from grazie.api.client.endpoints import GrazieApiGatewayUrls
from grazie.api.client.gateway import GrazieApiGatewayClient, GrazieAgent, AuthType
from grazie.api.client.profiles import LLMProfile

import config

client = GrazieApiGatewayClient(
    grazie_agent=GrazieAgent(name="commit-rewriting-synthetic-end-to-start", version="dev"),
    url=GrazieApiGatewayUrls.STAGING,
    auth_type=AuthType.SERVICE,
    grazie_jwt_token=config.GRAZIE_API_JWT_TOKEN
)


def generate_for_prompt(prompt):
    output = None

    while output is None:
        try:
            output = output = client.chat(
                chat=ChatPrompt()
                .add_system("You are a helpful assistant.")
                .add_user(prompt),
                profile=LLMProfile("gpt-4-1106-preview")
            ).content
        except:
            time.sleep(config.GRAZIE_TIMEOUT_SEC)

    assert output is not None

    return output