File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Network.HTTP.Client.TLS
6
6
import System.Environment (getEnv )
7
7
import qualified Data.Text as T
8
8
import Data.Maybe (fromMaybe )
9
+ import Data.Text (splitOn )
9
10
10
11
-- example derived from the openai-client library documentation
11
12
@@ -45,7 +46,20 @@ completionRequestToString prompt = do
45
46
return $ fromMaybe " No content" $ T. unpack <$> content
46
47
_ -> return " No choices returned"
47
48
49
+ -- find place names
50
+ findPlaces :: String -> IO [String ]
51
+ findPlaces text = do
52
+ let prompt = " Extract only the place names separated by commas from the following text:\n\n " ++ text
53
+ response <- completionRequestToString prompt
54
+ -- Convert Text to String using T.unpack before filtering
55
+ let places = filter (not . null ) $ map T. unpack $ splitOn " ," (T. pack response)
56
+ -- Strip leading and trailing whitespace from each place name
57
+ return $ map (T. unpack . T. strip . T. pack) places
58
+
48
59
main :: IO ()
49
60
main = do
50
61
response <- completionRequestToString " Write a hello world program in Haskell"
51
- putStrLn response
62
+ putStrLn response
63
+
64
+ places <- findPlaces " I visited London, Paris, and New York last year."
65
+ print places
You can’t perform that action at this time.
0 commit comments