What is the first science fiction work to feature a humanoid robot, that is at least partly an artificial intelligence? I don't mean exactly like R. Daniel Olivaw in Isaac Asimov's books, but also like R. Sammy, from the same series.
I think it sort of depends on what you mean by "artificial intelligence"--there are very old stories involving automata that resemble humans and sometimes act fairly intelligently, like Talos from the ancient Greek story of Jason and the Argonauts (or some of the other ancient Greek stories of automata listed here), but it may be hard to distinguish magic and fantasy from technology in such stories. Even after the scientific and industrial revolutions, some of the earliest stories of intelligent automata seem more fantastical than science fictional, like the 1814 story "Automata" by fantasy writer E. T. A. Hoffmann which can be read online here. An early example that seems more science fictional in nature would be the story of "Mr. Eisenbrass" from an 1848 issue of Scientific American, which you can find on the last page of this pdf, in the left-hand column.
A visitor who writes to the Augsburgh German Gazette, was invited with a friend to visit the Doctor's Sanctum. They beheld him seated at a key board similar to that of a piano forte and nearly in the centre of the room was a fashionably dressed young man, whom the Doctor introduced as a Mr. Eisenbrass, who wished the visitors good morning, and remained standing until they were seated. At first the conversation was upon the ordinary topics of the day-Mr. Eisenbrass joined with an occasional remark. but to which the Doctor paid very little attention, and kept amusing himself with the keys of the instrument, at which he was seated yet without producing any sound. This surprised the visitors, and one said, Doctor your instrument does not seem inclined to be musical at present. This brought a laugh from the Doctor, which was echoed by Mr. Eisenbrass, in such an unearthly and comical manner that the visitors had to laugh also, although they felt the laugh to be at their own expense. As soon as the visitors became calm the Dr. rose from his seat, and taking them calmly by the hand said, "Pardon me, my dear friends for having played an innocent prank upon you.—Mr. Eisenbrass is the Automaton I invited you here to see; and being the first who has seen it, I could not resist a sort of paternal desire of showing it off, as fond parents always do their first born children.
Although reading over this story, it's not clear if Mr. Eisenbrass actually has any independent intelligence--it may be that when the Doctor pushes keys on the keyboard, he selects the exact response Mr. Eisenbrass is giving, as opposed to just giving the automaton some general directions like "make polite small talk".
For another early candidate, there is Auguste de Villiers de L'Isle-Adam's novel L'Ève Future (Tomorrow's Eve) from 1886, as described in this article it sounds like the android has some independent intelligence even though programmed to be servile, a bit like a Stepford Wife or the Buffybot:
Since Alicia Clary—and by extension, all women—has proven herself unworthy of Lord Ewald's love, Edison will instead create for his friend a perfect specimen, the Eve of a new race of womanhood, “a combination of exquisite substances. . .[that make up] artificial flesh." A robot with Alicia's face, body, and mannerisms, but with a personality designed to cater to Ewald's every whim: “an Imitation Human Being, if you prefer” (p. 61). Edison implies that his creation will be as fully real as Alicia herself: “Her operation will be a little more dependent on electricity than that of her model; but that’s all” (p. 69). She is not the illusion of a woman, but the manifestation of the feminine ideal, mechanized and subject to male control.
But this review again seems to suggest some ambiguity about whether this android really has an artificial intelligence of its own (and if it does, whether it's purely technological or supernatural):
The great mystery of the book--how exactly Hadaly works--though it is elaborated upon at great length, is never clear. One moment, Hadaly is merely a glorified doll with a phonograph and a "central cylinder" inside dictating pre-recorded conversations and movements which Ewald will be able to choose by manipulating push-buttons hidden in her jewelry. But as she converses with both Ewald and Edison, Hadaly appears to be a fully independent and intelligent being, able to speak and act on her own. Then Edison indicates that Hadaly is operated remotely through a combination of electricity and telepathy by a woman kept in a mystical state by a combination of hypnosis and catatonia, and then there is a suggestion that Hadaly is in fact a sort of incarnation of a spirit descended into the world for the purpose either of leading Ewald to a higher plane, or else, perhaps, damning him to hell--and this spirit may or may not be the same person as the aforementioned catatonic telepath. The book seethes with the sense that a higher, fantastical world is ready any moment to burst in on the mundane world; this sense reaches its climax in a goosebump-raising speech of Hadaly to Ewald at the climax, in which she describes her true nature...or perhaps plays an elaborate ruse. It is tantalizingly unclear whether Hadaly merely contains a sophisticated recording of one woman, or of two, or whether she in fact contains the soul of a woman, or merely its imprint, or whether she is something else entirely, or whether she is one thing with the potential to be another.
Another female android built to be a wife can be found in "A Wife Manufactured to Order" (1895), available online here. Interestingly this one was by a female author, Alice W. Fuller; it critiques the idea that a wife should be perfectly agreeable and never express any independent thoughts, showing that the sexist man who thought he'd be happier with such a wife eventually grows bored and irritable with her and wants a real woman who thinks for herself. It's again a little unclear if the "electric wife" in the story has even a limited artificial intelligence, or if it just responds by playing back various canned phrases.
Yet another female android-as-wife story, Ernest Edward Kellett's "The New Frankenstein" from 1899, seems to involve a technological intelligence that can give answers to questions that aren't pre-recorded or given to it by a human (or human soul), see the description here:
Ernest Edward Kellett's "The New Frankenstein" trumped Edison's accomplishments—in fiction, at least. In it an inventor, Arthur Moore, develops an "anti-phonograph": "a triumph of civilisation" that, in the words of the narrator, can "give the appropriate answer to each question I like to put!" Like Edison's, Moore's instrument is fitted out with two tubes, a receiver (or "ear") and a speaker, from which emerges a "sweet and beautifully modulated feminine voice." He installs the anti-phonograph into "a creature that will guide herself, answer questions, talk and eat like a rational being, in fact, perform the part of a society lady."