Skip to content

Commit 40cfe19

Browse files
committed
added 'findPeople' to OpenAiApiClient example
1 parent f228b3c commit 40cfe19

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

OpenAiApiClient/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.codegpt

OpenAiApiClient/GenText.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,20 @@ findPlaces text = do
5656
-- Strip leading and trailing whitespace from each place name
5757
return $ map (T.unpack . T.strip . T.pack) places
5858

59+
findPeople :: String -> IO [String]
60+
findPeople text = do
61+
let prompt = "Extract only the person names separated by commas from the following text:\n\n" ++ text
62+
response <- completionRequestToString prompt
63+
let people = filter (not . null) $ map T.unpack $ splitOn "," (T.pack response)
64+
return $ map (T.unpack . T.strip . T.pack) people
65+
5966
main :: IO ()
6067
main = do
6168
response <- completionRequestToString "Write a hello world program in Haskell"
6269
putStrLn response
6370

6471
places <- findPlaces "I visited London, Paris, and New York last year."
65-
print places
72+
print places
73+
74+
people <- findPeople "John Smith met with Sarah Johnson and Michael Brown at the conference."
75+
print people

0 commit comments

Comments
 (0)