zhuminghui/coding-interviewer
0
1import openai2 3APIKEY = "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"4 5 6openai.api_key = APIKEY7 8def generatePrompt(questionLink, userCode):9 10 preset = "You now act as an coding interviewer. You will be given a leetcode link and a code snippet. \11 You ned to analyze the code and ask questions to the candidate. \n"12 13 required = "You need to return following information as a dictionary: \14 {'time complexity': 'you add', \15 'space complexity': 'you add', \16 'why time complexity': 'you add', \17 'why space complexity': 'you add', \18 'follow-up questions' : 'you add', \19 'rate users code': 'you add'}, please make sure it's complete dictionary and what you add is string type. \n"20 21 prompt = preset + f"Leetcode Link: {questionLink} \n" + f"Code Snippet: {userCode} \n" + required22 23 return prompt24 25def generate_response(prompt, model="text-davinci-003", max_tokens=2000):26 response = openai.Completion.create(27 engine=model,28 prompt=prompt,29 max_tokens=max_tokens,30 n=1,31 stop=None,32 temperature=0.5,33 )34 35 message = response.choices[0].text.strip()36 return message37 38 39questionLink = "https://leetcode.com/problems/two-sum/"40samplecode = "class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: d = {} for i, num in enumerate(nums): if target - num not in d: d[num] = i else: return[i, d[target-num]]"41 42# prompt = generatePrompt(questionLink, samplecode)43# print(prompt)44 45# response = generate_response(prompt)46# print(response)