Skip to content

Commit

Permalink
Fixed more dialyzer errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Idorobots committed May 10, 2023
1 parent 215c5d8 commit 1b39760
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/xmppgpt_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ process_prompt(Id, Prompt) ->

%% Callbacks
init([_Url, _ApiKey, OrgId | _ ] = Args) ->
lager:info("Started with organization: ~p~n", [OrgId]),
ok = lager:info("Started with organization: ~p~n", [OrgId]),
ok = hackney_pool:start_pool(?MODULE, [{timeout, ?POOL_TIMEOUT}]),
{ok, Args}.

terminate(_Reason, _State) ->
hackney_pool:stop_pool(?MODULE).

handle_call(Request, _From, State) ->
lager:warning("Got unknown request: ~n~p~n~n", [Request]),
ok = lager:warning("Got unknown request: ~n~p~n~n", [Request]),
{noreply, State}.

handle_cast({prompt, Id, Prompt, From}, State) ->
lager:debug("Got a prompt request: ~n~p~n~n", [Prompt]),
ok = lager:debug("Got a prompt request: ~n~p~n~n", [Prompt]),
_ = send_request(From, Id, Prompt, State),
{noreply, State};

handle_cast(Request, State) ->
lager:warning("Got unknown request: ~n~p~n~n", [Request]),
ok = lager:warning("Got unknown request: ~n~p~n~n", [Request]),
{noreply, State}.

send_request(From, Id, Prompt, [Url, ApiKey, _OrgId, Model, Temp]) ->
Expand Down Expand Up @@ -78,7 +78,7 @@ handle_response(From, Id, #{<<"choices">> := Responses}) ->
From ! {prompt_response, Id, Response};

handle_response(From, Id, Response) ->
lager:warning("Got unknown resopnse: ~n~p~n~n", [Response]),
ok = lager:warning("Got unknown resopnse: ~n~p~n~n", [Response]),
From ! {prompt_response, Id, "Got an unknown response from ChatGPT."}.

combine_responses(#{<<"message">> := #{<<"content">> := Response}}, Acc) ->
Expand Down
2 changes: 1 addition & 1 deletion src/xmppgpt_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-export([start/2, stop/1]).

start(_StartType, StartArgs) ->
lager:info("Started with: ~p~n", [StartArgs]),
ok = lager:info("Started with: ~p~n", [StartArgs]),
{ok, Server} = application:get_env(server),
{ok, Port} = application:get_env(port),
{ok, Username} = application:get_env(username),
Expand Down
22 changes: 11 additions & 11 deletions src/xmppgpt_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ callback_mode() ->
state_functions.

init([Server, Port, Username, Domain, Password] = Args) ->
lager:info("Started with: ~p~n", [Args]),
ok = lager:info("Started with: ~p~n", [Args]),
Session = exmpp_session:start_link({1, 0}),
JID = exmpp_jid:make(Username, Domain, random),
exmpp_session:auth(Session, JID, Password, ?METHOD),
Expand All @@ -31,7 +31,7 @@ init([Server, Port, Username, Domain, Password] = Args) ->
_ = try exmpp_session:login(Session, ?METHOD)
catch
throw:{auth_error, 'not-authorized'} ->
lager:info("Registering user...~n", []),
ok = lager:info("Registering user...~n", []),
exmpp_session:register_account(Session, Password),
exmpp_session:login(Session, ?METHOD)
end,
Expand All @@ -48,19 +48,19 @@ listening(info, #received_packet{
raw_packet=Packet,
type_attr=Type
} = Record, Session) when Type =/= "error" ->
lager:debug("Received Message stanza:~n~p~n~n", [Record]),
ok = lager:debug("Received Message stanza:~n~p~n~n", [Record]),
handle_packet(Session, Packet);

listening(info, Record, Session) when Record#received_packet.packet_type == 'presence' ->
lager:debug("Received Presence stanza:~n~p~n~n", [Record]),
ok = lager:debug("Received Presence stanza:~n~p~n~n", [Record]),
handle_presence(Session, Record, Record#received_packet.raw_packet);

listening(info, Record, Session) ->
lager:debug("Received a stanza:~n~p~n~n", [Record]),
ok = lager:debug("Received a stanza:~n~p~n~n", [Record]),
{keep_state, Session};

listening(EventType, _EventContent, Session) ->
lager:warning("Got unknown event type: ~n~p~n~n", [EventType]),
ok = lager:warning("Got unknown event type: ~n~p~n~n", [EventType]),
{keep_state, Session}.

awaiting_response(info, {prompt_response, {Id, To, From}, Response}, Session) ->
Expand All @@ -72,19 +72,19 @@ awaiting_response(info, #received_packet{
raw_packet=Packet,
type_attr=Type
} = Record, Session) when Type =/= "error" ->
lager:debug("Received Message stanza:~n~p~n~n", [Record]),
ok = lager:debug("Received Message stanza:~n~p~n~n", [Record]),
From = exmpp_xml:get_attribute(Packet, <<"from">>, <<"unknown">>),
To = exmpp_xml:get_attribute(Packet, <<"to">>, <<"unknown">>),
Id = exmpp_xml:get_attribute(Packet, <<"id">>, <<"unknown">>),
respond(Session, Id, To, From, "Busy..."),
{keep_state, Session};

awaiting_response(info, Record, Session) when Record#received_packet.packet_type == 'presence' ->
lager:debug("Received Presence stanza:~n~p~n~n", [Record]),
ok = lager:debug("Received Presence stanza:~n~p~n~n", [Record]),
handle_presence(Session, Record, Record#received_packet.raw_packet);

awaiting_response(EventType, _EventContent, Session) ->
lager:warning("Got unknown event type: ~n~p~n~n", [EventType]),
ok = lager:warning("Got unknown event type: ~n~p~n~n", [EventType]),
{keep_state, Session}.

%% Logic
Expand All @@ -97,7 +97,7 @@ handle_packet(Session, Packet) ->
%% Typing indication, etc.
{keep_state, Session};
Body ->
lager:debug("Processing ChatGPT prompt: ~n~p~n~n", [Body]),
ok = lager:debug("Processing ChatGPT prompt: ~n~p~n~n", [Body]),
xmppgpt_api:process_prompt({Id, To, From}, Body),
{next_state, awaiting_response, Session}
end.
Expand Down Expand Up @@ -135,5 +135,5 @@ presence_subscribe(Session, Recipient) ->
send_packet(Session, Presence).

send_packet(Session, Packet) ->
lager:debug("Sending stanza: ~n~p~n~n", [Packet]),
ok = lager:debug("Sending stanza: ~n~p~n~n", [Packet]),
exmpp_session:send_packet(Session, Packet).

0 comments on commit 1b39760

Please sign in to comment.